|
|
back to boardWhy WA#1? 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 = ' '; } } |
|
|