POJ 2230 Watchcow

题意:反正就是让你从1开始输出欧拉回路的路径

题解:我也不是特别理解的套圈法

Watchcow

 1 #include<cstring>
 2 #include<iostream>
 3 using namespace std;
 4 const int N = 20000+5;
 5 int head[N];
 6 int cnt = 0, n, m;
 7 struct Node
 8 {
 9     int nx;
10     int to;
11     bool vis;
12 }Edge[N*5];
13 void add_edge(int u, int v)
14 {
15     Edge[cnt].to = v;
16     Edge[cnt].nx = head[u];
17     Edge[cnt].vis = 1;
18     head[u] = cnt++;
19 }
20 void dfs(int u)
21 {
22     for(int i = head[u]; ~i; i = Edge[i].nx)
23     {
24         if(Edge[i].vis)
25         {
26             Edge[i].vis = 0;
27             dfs(Edge[i].to);
28         }
29     }
30     cout << u << endl;
31 }
32 int main()
33 {
34     ios::sync_with_stdio(false);
35     cin.tie(0);
36     memset(head, -1, sizeof(head));
37     cin >> n >> m;
38     int u, v;
39     for(int i = 1; i <= m; i++)
40     {
41         cin >> u >> v;
42         add_edge(u, v);
43         add_edge(v, u);
44     }
45     dfs(1);
46     return 0;
47 }
原文地址:https://www.cnblogs.com/MingSD/p/8418970.html