idea: Similar to a topological sorting problem, according to the degree of 1 points, it is connected to the number of edges is different or and this rule, directly to the topological sort.
Each time the resulting node is reduced by one, and xor the node he or she is connected to.
Code:
#include <cstdio> #include <cstring> #include <iostream> #include <vector> #include < Algorithm> #include <queue>using namespace std;typedef long long ll;vector<int> g[66000];int n,de[66000] , Sum[66000];void Solve () {queue<int> q; while (!q.empty ()) Q.pop (); for (int i=0;i<n;i++) if (de[i]==1) Q.push (i); while (!q.empty ()) {int xo=0; int V=q.front (); Q.pop (); if (de[v]!=1) continue; int U=SUM[V]; sum[u]^=v,de[u]--; if (de[u]==1) Q.push (U); printf ("%d%d\n", v,u); }}int Main () {//freopen ("In.txt", "R", stdin); int m=0; scanf ("%d", &n); for (int i=0;i<n;i++) {scanf ("%d%d", &de[i],&sum[i]); M+=de[i]; } printf ("%d\n", M/2); Solve (); return 0;}
Codeforces Round #285 (Div. 2) C-misha and Forest