Question: A graph deletes two adjacent edges each time and asks if all edges can be deleted.
Solution: if each connected component of the graph has an even number of edges, 1 is output; otherwise, 0 is output;
# Include <cstdio> # include <cstring> # include <algorithm> using namespace STD; int parent [10000], depth [10000]; void make_set (int x) {parent [x] = x; depth [x] = 0;} int find (int x) {If (parent [x]! = X) parent [x] = find (parent [x]); Return parent [X];} void Union (int u, int v) {u = find (U ); V = find (V); If (u = V) return; If (depth [u] <depth [v]) {parent [u] = V ;} else {parent [v] = u; If (depth [u] = depth [v]) + + depth [u] ;}} int main () {int U, v, n = 0, deg [10000]; memset (deg, 0, sizeof (DEG); For (INT I = 0; I <10000; ++ I) make_set (I); While (scanf ("% d", & U, & V) = 2) {n = max (n, max (u, (v); -- U; -- V; Union (u, v); ++ deg [u]; ++ deg [v];} int cont [10000]; memset (cont, 0, sizeof (cont); For (INT I = 0; I <n; ++ I) cont [find (I)] + = deg [I]; bool odds = false; For (INT I = 0; I <n; ++ I) if (cont [I] & 2) odds = true; if (odds) puts ("0"); else puts ("1"); Return 0 ;}