标签:style color io os ar strong for 数据 art
3 3 1 2 1 3 2 3 3 2 1 2 2 3 0
样例输出:
1
0
#include <iostream> using namespace std; const int max = 1001; int G[max][max]; int du[max]; bool visite[max]; int n, m; bool judge() { for (int i = 1; i <= n; i++) { if (du[i] % 2 != 0 || du[i] == 0) return false; } return true; } void DFS(int start, int &counts) { for (int i = 1; i <= n; i++) { if (G[start][i] && !visite[i]) { counts++; visite[i] = true; DFS(i, counts); } } } int main() { int s, e, counts; cin >> n; while (n!=0) { counts = 1; for (int i = 0; i <= n;i++) for (int j = 0; j <= n; j++) { G[i][j] = 0; } for (int i=0;i<=n;i++) { du[i] = 0; visite[i] = false; } cin >> m; for (int i = 0; i <m; i++) { cin >> s >> e; G[s][e] = 1; G[e][s] = 1; du[s]++; du[e]++; } visite[1] = true;; DFS(1, counts); if (counts == n&&judge()) cout << "1" << endl; else cout << "0" << endl; cin >> n; } return 0; }
标签:style color io os ar strong for 数据 art
原文地址:http://blog.csdn.net/leviathan_/article/details/39255757