ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1106. Two Teams

Why WA#1?
Posted by Artem Khizha 31 Jan 2010 19:20
I've already solved this problem in Pascal, but now I'm trying to get through with my C++ code. I see no difference to my accepted solution and interested, what the point.

Can someone help me to understand?

Compiled with Gnu C++ compiler.
#include <cstdio>
#include <vector>

#define ___MAXN 1000

typedef unsigned int uint;
std::vector< std::vector<int> > G(0);
int col[___MAXN] = {0};

void dfs(uint u, uint c)  {
    col[u] = c;
    for (uint v=0; v<G[u].size(); v++)
        if (!col[G[u][v]])
            dfs(G[u][v], 3-col[u]);
}

void colorize() {
    for (uint u=0; u<G.size(); u++)
        if (!col[u])
            dfs(u, 1);
}

int main()  {
    uint n;
    scanf("%u", &n);
    G.resize(n);

    for (uint i=0; i<n; i++) {
        static uint x;
        scanf("%u", &x);
        do  {
            G[i].push_back(x-1);
            scanf("%u", &x);
        }   while (x);
    }
    colorize();
    n = 0;
    for (uint i=0; i<G.size(); i++)
        switch (col[i]) {
        case 0:
            printf("0\n");
            return 0;
        case 1:
            n++;
            break;
        }
    printf("%u\n", n);
    char c = 0;
    for (uint i=0; i<G.size(); i++)
        if (col[i]==1)  {
            printf("%c%u", c, i+1);
            c = ' ';
        }
}