제출 #156368

#제출 시각아이디문제언어결과실행 시간메모리
156368AkashiPotemkin cycle (CEOI15_indcyc)C++14
40 / 100
1101 ms528148 KiB
#include <bits/stdc++.h> using namespace std; int n, m; bool ad[1005][1005]; bool viz[1005]; int f[1005], TT[1005]; vector <int> v[1005]; vector <int> sol; queue <int> q; void find_path(int x, int y){ q.push(x); viz[y] = 0; while(!q.empty()){ int nod = q.front(); q.pop(); for(auto it : v[nod]) if(!viz[it]) viz[it] = 1, TT[it] = nod, q.push(it); } while(y != x){ sol.push_back(y); y = TT[y]; } sol.push_back(x); } bool find(int nod){ for(auto it : v[nod]) if(!f[it]) f[it] = 3, q.push(it); if(q.empty()) return 0; set <int> nodes; nodes.insert(nod); while(!q.empty()){ int nod = q.front(); q.pop(); for(auto it : v[nod]){ if(!f[it]) f[it] = 3, q.push(it); if(f[it] == 2) nodes.insert(it); } } for(auto x : nodes){ for(auto y : nodes){ if(!ad[x][y] && x != y){ find_path(x, y); return 1; } } } return 0; } bool solve(int nod){ f[nod] = 1; viz[nod] = 1; for(auto it : v[nod]) viz[it] = 1, f[it] = 2; for(auto it : v[nod]) if(find(it)) return 1; return 0; } int main() { // freopen("1.in", "r", stdin); scanf("%d%d", &n, &m); int x, y; for(int i = 1; i <= m ; ++i){ scanf("%d%d", &x, &y); v[x].push_back(y); v[y].push_back(x); ad[x][y] = ad[y][x] = 1; } for(int i = 1; i <= n ; ++i){ sol.push_back(i); memset(f, 0, sizeof(f)); memset(viz, 0, sizeof(viz)); if(solve(i)) break ; sol.pop_back(); } if(sol.size() == 0) printf("no"); else for(auto it : sol) printf("%d ", it); return 0; }

컴파일 시 표준 에러 (stderr) 메시지

indcyc.cpp: In function 'int main()':
indcyc.cpp:70:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~
indcyc.cpp:74:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &x, &y);
         ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...