Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
判断连通的时猴,嫑㞎没有開着的門的點祘进去#include <iostream> #include <string> #include <sstream> #include <vector> using namespace std; vector<int> adjList[25]; void dfs(int m, bool *used){ used[m] = 1; int sz = adjList[m].size(); for(int i = 0; i < sz; i++){ if(used[adjList[m][i]]) continue; dfs(adjList[m][i], used); } } int main() { while(1){ string s; getline(cin, s); if(s == "ENDOFINPUT") break; stringstream ss; ss << s; string fei; int M, N; ss >> fei >> M >> N; //cout << M << " " << N << endl; int cnt = 0; for(int i = 0; i < N; i++) adjList[i].clear(); bool ymkz[25] = {0}; for(int i = 0; i < N; i++){ getline(cin, s); //cout << s << endl; stringstream sss; sss << s; int temp; while(sss >> temp){ cnt++; adjList[i].push_back(temp); adjList[temp].push_back(i); ymkz[i] = 1; ymkz[temp] = 1; } } getline(cin, fei); bool used[25] = {0}; dfs(M, used); bool ky = 1; for(int i = 0; i < N; i++){ if(ymkz[i] && !used[i]){ ky = 0; break; } } if(!ky){ cout << "NO" << endl; continue; } if(M == 0){ for(int i = 0; i < N; i++){ if(adjList[i].size()%2 != 0){ ky = 0; break; } } } else{ if(adjList[0].size()%2==0 || adjList[M].size()%2==0){ ky = 0; } else{ for(int i = 1; i < N; i++){ if(i == M) continue; if(adjList[i].size()%2){ ky = 0; break; } } } } if(ky){ cout << "YES " << cnt << endl; } else cout << "NO" << endl; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator