题目描述
http://main.edu.pl/en/archive/oi/18/smi
The Byteotian Waste Management Company (BWMC) has drastically raised the price of garbage collection lately. This caused some of the citizens to stop paying for collecting their garbage and start disposing of it in the streets. Consequently, many streets of Byteburg are literally buried under litter.
The street system of Byteburg consists of intersections, some of which are directly connected with bidirectional streets. No two streets connect the same pair of intersections. Some of the streets are littered while others are not.
The mayor of Byteburg, Byteasar, has decided on an unprecedented action to persuade the citizens to pay for waste collection. Namely, he decided to clean only some of the streets - precisely those that the majority of people living on paid for garbage collection. The streets that the majority of people living on did not pay for waste collection, on the other hand, will thus remain littered - or if it is called for - will become littered by the garbage collected from other streets! Byteasar has already prepared a city map with the streets to be cleaned and to remain or become littered marked on. Unfortunately, the BWMC employees cannot comprehend his master plan. They are, however, quite capable of carrying out simple instructions.
A single such instruction consists in driving the garbage truck along a route that starts on an arbitrary intersection, goes along any streets of choice, and ending on the very same intersection that it started on. However, every intersection can be visited at most once on a single route, except for the one it starts and ends with-the garbage truck obviously appears twice on that one. The truck cleans a littered street it rides along, but on the other hand it dumps the waste on the clean streets along its route, making them littered.
Byteasar wonders if it is possible to execute his plan by issuing a number of aforementioned route instructions. Help him out by writing a program that determines a set of such routes or concludes that it is impossible.
给定n个点m条边,每条边有一个初始权值0或1,有一个最终权值0或1,每次可以给一个简单环上的边权值异或1,求一种方案使得每条边从初始权值变成最终权值,无解输出"NIE"
输入输出样例
2 3 1 3 2 1 3 4 6 5 4
分析:
模板题em。。。欧拉回路中最简单的一道题。。。然而我不会???因为我第一个做这题的。。。
CODE:
来源于https://loj.ac/submission/512425
1 #include <iostream> 2 #include <cstring> 3 #include <cstdio> 4 #include <vector> 5 6 const int maxn = 1e5 + 7; 7 const int maxm = 2e6 + 7; 8 9 using namespace std; 10 11 int cnt; 12 int d[maxn]; 13 int to[maxm]; 14 int nex[maxm]; 15 int last[maxn], k = 1; 16 int q[maxn], top; 17 int inq[maxn]; 18 int vis[maxm]; 19 vector<int> ans[maxn]; 20 21 inline int read() { 22 int x = 0; 23 char ch = getchar(); 24 while (ch < '0' || ch > '9') ch = getchar(); 25 while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar(); 26 return x; 27 } 28 29 int rit[25], rits; 30 void write(int x) { 31 for (int i; x; x = i) i = x / 10, rit[++rits] = x - i * 10; 32 while (rits) putchar(rit[rits--] + '0'); 33 } 34 35 inline void add_edge(int x, int y) { 36 to[++k] = y; 37 nex[k] = last[x]; 38 last[x] = k; 39 } 40 41 void dfs(int x) { 42 if (inq[x]) { 43 ++cnt; 44 int y = 0; 45 do 46 y = q[top--], inq[y] = 0, ans[cnt].push_back(y); 47 while (y != x); 48 } 49 for (int &i = last[x]; i; i = nex[i]) 50 if (!vis[i]) 51 vis[i] = vis[i ^ 1] = 1, inq[q[++top] = x] = 1, dfs(to[i]); 52 } 53 54 int main(void) { 55 int n = read(), m = read(); 56 while (m--) { 57 int x = read(), y = read(), a = read(), b = read(); 58 if (a ^ b) { 59 add_edge(x, y); 60 add_edge(y, x); 61 d[x] ^= 1; 62 d[y] ^= 1; 63 } 64 } 65 for (register int i = 1; i <= n; i++) 66 if (d[i]) { 67 cout << "NIE\n"; 68 return 0; 69 } 70 for (register int i = 1; i <= n; i++) dfs(i); 71 write(cnt), putchar('\n'); 72 for (register int i = 1; i <= cnt; i++) { 73 write(ans[i].size()), putchar(' '); 74 for (int j = 0; j < ans[i].size(); j++) write(ans[i][j]), putchar(' '); 75 write(ans[i][0]), putchar('\n'); 76 } 77 78 return 0; 79 }