Topic Portal
1 /*2 Test instructions: gives a non-circular graph, the degree of each point and the xor of the adjacent points (a^b^c^ ...)3 graph theory/bit operations: In fact, the problem is very simple. Similar topological sort, first in the degree of 1 first-in pairs, each one less than one degree4 the key is to update the XOR, the essence: a ^ b = c, a ^ c = b, b ^ c = A;5 */6#include <cstdio>7#include <cstring>8#include <cmath>9#include <algorithm>Ten#include <queue> One using namespacestd; A - Const intMAXN = 7e4 +Ten; - Const intINF =0x3f3f3f3f; the intans[maxn][2]; - intD[MAXN], S[MAXN]; - - intMainvoid)//codeforces Round #285 (Div. 2) C. Misha and Forest + { - //freopen ("c.in", "R", stdin); + A intN; at while(SCANF ("%d", &n) = =1) - { -queue<int>Q; - for(intI=0; i<n; ++i) - { -scanf ("%d%d", &d[i], &s[i]); in if(D[i] = =1) Q.push (i); - } to + intCNT =0; - while(!q.empty ()) the { * intU =Q.front (); Q.pop (); $ if(D[u] = =0)Continue;Panax Notoginseng intv =S[u]; -ans[++cnt][0] = u; ans[cnt][1] =v; the if((--d[v]) = =1) Q.push (v); +S[V] = S[v] ^u; A } the +printf ("%d\n", CNT); - for(intI=1; i<=cnt; ++i) $ { $printf ("%d%d\n", ans[i][0], ans[i][1]); - } - } the - return 0;Wuyi}
Graph theory/bit operations codeforces Round #285 (Div. 2) C. Misha and Forest