제출 #246558

#제출 시각아이디문제언어결과실행 시간메모리
246558dantoh000Potemkin cycle (CEOI15_indcyc)C++14
50 / 100
553 ms8892 KiB
#include <bits/stdc++.h> using namespace std; int n,m; int id[1005][1005]; int A[1005]; int B[1005]; int vis[100005]; vector<int> ans; int cycle; bool dfs(int a, int b){ vis[id[a][b]] = 2; for (int c = 1; c <= n; c++){ if (c != a && id[b][c] && !id[a][c]){ if (vis[id[b][c]] == 2){ cycle = b; ans.push_back(b); ans.push_back(a); return true; } else if (dfs(b,c)){ ans.push_back(a); if (id[a][cycle]){ //for (auto x : ans) printf("%d ",x); for (int x = 0; x < ans.size(); x++){ for (int y = x+2; y < ans.size(); y++){ if ((ans[x] == ans[y] || id[ans[x]][ans[y]]) && (x != 0 || y != ans.size()-1)){ ///xxx illegal operation //printf("%d -> %d illegal \n",ans[x],ans[y]); ///delete everything in it (N * N is ok) ans.erase(ans.begin()+x, ans.begin()+y+1); y = x+1; ///restart check } } } if (ans.size() > 3){ for (auto x : ans) printf("%d ",x); exit(0); } } return true; } } } vis[id[a][b]] = 1; return false; } int main(){ scanf("%d%d",&n,&m); for (int i = 1; i <= m; i++){ scanf("%d%d",&A[i],&B[i]); id[B[i]][A[i]] = id[A[i]][B[i]] = i; } for (int i = 1; i <= m; i++){ if (vis[i] == 0) { dfs(A[i],B[i]); ans.clear(); } } printf("no"); }

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

indcyc.cpp: In function 'bool dfs(int, int)':
indcyc.cpp:25:39: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                     for (int x = 0; x < ans.size(); x++){
                                     ~~^~~~~~~~~~~~
indcyc.cpp:26:45: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                         for (int y = x+2; y < ans.size(); y++){
                                           ~~^~~~~~~~~~~~
indcyc.cpp:27:90: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
                             if ((ans[x] == ans[y] || id[ans[x]][ans[y]]) && (x != 0 || y != ans.size()-1)){ ///xxx illegal operation
                                                                                        ~~^~~~~~~~~~~~~~~
indcyc.cpp: In function 'int main()':
indcyc.cpp:49: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:51:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d",&A[i],&B[i]);
         ~~~~~^~~~~~~~~~~~~~~~~~~~
#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...