Submission #152635

#TimeUsernameProblemLanguageResultExecution timeMemory
152635ansol4328Cactus? Not cactus? (kriii1_C)C++11
1 / 1
90 ms12024 KiB
#include<bits/stdc++.h> using namespace std; int n, m; vector<int> lst[100005]; bool visit[100005], cyc[100005]; int cnt, cur[100005], vlst[100005]; bool cactus=true; void dfs(int v, int prev) { if(cur[v]!=0){ if(cactus){ for(int i=cur[v] ; i<=cnt ; i++){ if(cyc[vlst[i]]) cactus=false; cyc[vlst[i]]=true; } } return; } if(visit[v]) return; cnt++; visit[v]=true; cur[v]=cnt; vlst[cnt]=v; for(int i=0 ; i<lst[v].size() ; i++){ int nxt=lst[v][i]; if(nxt!=prev) dfs(nxt,v); } cnt--; cur[v]=0; } int main() { scanf("%d %d",&n,&m); for(int i=1 ; i<=m ; i++){ int x, y; scanf("%d %d",&x,&y); lst[x].push_back(y); lst[y].push_back(x); } for(int i=1 ; i<=n ; i++) if(!visit[i]) dfs(i,-1); printf("%s",cactus ? "Cactus" : "Not cactus"); return 0; }

Compilation message (stderr)

C.cpp: In function 'void dfs(int, int)':
C.cpp:27:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0 ; i<lst[v].size() ; i++){
                   ~^~~~~~~~~~~~~~
C.cpp: In function 'int main()':
C.cpp:37:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d",&n,&m);
     ~~~~~^~~~~~~~~~~~~~~
C.cpp:40: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...