Sponsors

Codeforces Round #383 (Div. 2), problem: (E) Arpa’s overnight party and Mehrdad’s silent entering Solution in C/C++

#include <stdio.h>
#include <string.h>

int n,a[200010],b[200010],c[200010],p[200010];
void dfs(int k,int col);

int main(void)
{
    //freopen("party.in","r",stdin);
    //freopen("party.out","w",stdout);
    scanf("%d",&n);
    int i;
    for(i=1;i<=n;i++)
    {
        scanf("%d%d",&a[i],&b[i]);
        p[a[i]]=b[i];  p[b[i]]=a[i];
    }
    memset(c,0,sizeof(c));
    for(i=1;i<=n*2;i++)
        if(!c[i]) dfs(i,0);
    for(i=1;i<=n;i++)
        printf("%d %d\n",c[a[i]],c[b[i]]);
    return 0;
}

void dfs(int k,int col)
{
    c[k]=col+1;
    if(!c[((k-1)^1)+1])
        dfs(((k-1)^1)+1,col^1);
    else if(!c[p[k]]) dfs(p[k],col^1);
    else return;
}

Judge sentences Australian woman...

Australian Woman Receives Life Sentence for Fatal Mushroom Poisoning Erin...

Chainsaw Man – The...

Chainsaw Man Movie's Reze Arc: Maximum the Hormone Returns! Fans...

You can still save...

Score Big Savings on Steelcase Furniture: Extended Labor Day...

Apple has reportedly launched...

Apple's Internal AI Chatbot: A Retail-Focused Approach Apple, a company...

Solana’s U.S. backing vs....

Solana's U.S. Backing vs. Binance's Asian Capital: A Crypto...

Why Trump Won’t Tell...

Why Trump Won't Tell the Truth About His Health:...

Judge sentences Australian woman to life in prison for fatal mushroom poisoning of in-laws

Australian Woman Receives Life Sentence for Fatal Mushroom Poisoning Erin Patterson, an Australian woman, has been sentenced to life in prison for the fatal mushroom...

Chainsaw Man – The Movie: Reze Arc Anime Announces Insert Song Artist

Chainsaw Man Movie's Reze Arc: Maximum the Hormone Returns! Fans of Chainsaw Man are in for a treat! The upcoming anime movie focusing on...

You can still save 20% off Steelcase office chairs and desks during this extended Labor Day sale

Score Big Savings on Steelcase Furniture: Extended Labor Day Sale! Labor Day may be over, but the deals aren't! Steelcase, a renowned name in...

Apple has reportedly launched an AI chatbot, but it’s not for the iPhone 17 (or you)

Apple's Internal AI Chatbot: A Retail-Focused Approach Apple, a company synonymous with consumer-facing technology, has reportedly launched its own AI chatbot. However, unlike the...

Solana’s U.S. backing vs. Binance’s Asian capital: Who will win this battle?

Solana's U.S. Backing vs. Binance's Asian Capital: A Crypto Clash for Supremacy The cryptocurrency landscape is a volatile battlefield, and a fascinating clash is brewing...

Why Trump Won’t Tell the Truth About His Health: Michael Wolff | Inside Trump’s Head

Why Trump Won't Tell the Truth About His Health: Decoding Michael Wolff's Insights Michael Wolff, a controversial yet impactful figure in political journalism, recently offered...

Mapping the Jazz Faculty Gender Gap

Mapping the Jazz Faculty Gender Gap: A Berklee-Sponsored Study Reveals Stark Imbalance A recently published study sponsored by Berklee College of Music paints a concerning...

Burning Man festivalgoer is found dead in pool of blood as cops launch murder probe

Burning Man Festivalgoer Found Dead in Pool of Blood; Murder Investigation Launched A tragic incident has cast a shadow over the iconic Burning Man festival...

Fleischmann says ‘never’ to town hall (Ruby Rayner/timesfreepress.com)

Fleischmann Declares 'Never' to Town Halls, Calling Them 'Left-Wing Bait' Chattanooga Congressman Chuck Fleischmann has emphatically ruled out holding town hall meetings, labeling them as...