Submission #152635

# Submission time Handle Problem Language Result Execution time Memory
152635 2019-09-08T18:13:27 Z ansol4328 Cactus? Not cactus? (kriii1_C) C++11
1 / 1
90 ms 12024 KB
#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

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 time Memory Grader output
1 Correct 5 ms 2808 KB Output is correct
2 Correct 4 ms 2680 KB Output is correct
3 Correct 6 ms 2936 KB Output is correct
4 Correct 6 ms 2936 KB Output is correct
5 Correct 6 ms 2936 KB Output is correct
6 Correct 6 ms 2936 KB Output is correct
7 Correct 7 ms 2936 KB Output is correct
8 Correct 6 ms 2936 KB Output is correct
9 Correct 7 ms 2936 KB Output is correct
10 Correct 43 ms 6904 KB Output is correct
11 Correct 35 ms 6384 KB Output is correct
12 Correct 48 ms 8312 KB Output is correct
13 Correct 59 ms 7672 KB Output is correct
14 Correct 54 ms 7416 KB Output is correct
15 Correct 58 ms 9464 KB Output is correct
16 Correct 46 ms 7456 KB Output is correct
17 Correct 42 ms 8312 KB Output is correct
18 Correct 80 ms 11128 KB Output is correct
19 Correct 90 ms 12024 KB Output is correct
20 Correct 47 ms 7720 KB Output is correct
21 Correct 86 ms 8016 KB Output is correct
22 Correct 58 ms 9876 KB Output is correct
23 Correct 4 ms 2808 KB Output is correct
24 Correct 4 ms 2680 KB Output is correct
25 Correct 9 ms 3500 KB Output is correct
26 Correct 67 ms 7144 KB Output is correct
27 Correct 28 ms 4600 KB Output is correct
28 Correct 49 ms 6520 KB Output is correct
29 Correct 58 ms 6648 KB Output is correct
30 Correct 52 ms 6648 KB Output is correct
31 Correct 59 ms 6472 KB Output is correct
32 Correct 67 ms 7012 KB Output is correct
33 Correct 66 ms 7048 KB Output is correct
34 Correct 73 ms 7016 KB Output is correct