답안 #5712

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
5712 2014-05-14T10:37:02 Z baneling100 Cactus? Not cactus? (kriii1_C) C++
1 / 1
68 ms 11752 KB
#include <stdio.h>
#include <stdlib.h>
#include <vector>

using namespace std;

vector <int> A[100001];
int N, M, S[100001], top, check[100001], cycle[100001];

void input(void)
{
    int i, x, y;

    scanf("%d %d",&N,&M);
    for(i=1 ; i<=M ; i++)
    {
        scanf("%d %d",&x,&y);
        A[x].push_back(y);
        A[y].push_back(x);
    }
}

void process(int now, int prev)
{
    int i, j, k;

    j=A[now].size();
    for(i=0 ; i<j ; i++)
        if(A[now][i]!=prev)
        {
            if(check[A[now][i]])
                for(k=check[A[now][i]] ; k<=top ; k++)
                {
                    if(cycle[S[k]])
                    {
                        printf("Not cactus");
                        exit(0);
                    }
                    else
                        cycle[S[k]]=1;
                }
            else
            {
                S[++top]=A[now][i];
                check[A[now][i]]=top;
                process(A[now][i],now);
                top--;
            }
        }
}

int main(void)
{
    input();
    S[++top]=1;
    check[1]=top;
    process(1,0);
    top--;
    printf("Cactus");

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 4720 KB Output is correct
2 Correct 0 ms 4720 KB Output is correct
3 Correct 4 ms 4852 KB Output is correct
4 Correct 0 ms 4720 KB Output is correct
5 Correct 0 ms 4720 KB Output is correct
6 Correct 0 ms 4852 KB Output is correct
7 Correct 4 ms 4852 KB Output is correct
8 Correct 0 ms 4852 KB Output is correct
9 Correct 4 ms 4852 KB Output is correct
10 Correct 36 ms 7624 KB Output is correct
11 Correct 32 ms 7472 KB Output is correct
12 Correct 32 ms 8816 KB Output is correct
13 Correct 36 ms 8128 KB Output is correct
14 Correct 48 ms 7928 KB Output is correct
15 Correct 52 ms 9740 KB Output is correct
16 Correct 40 ms 8052 KB Output is correct
17 Correct 28 ms 8888 KB Output is correct
18 Correct 60 ms 10964 KB Output is correct
19 Correct 68 ms 11752 KB Output is correct
20 Correct 32 ms 8368 KB Output is correct
21 Correct 48 ms 8112 KB Output is correct
22 Correct 44 ms 10152 KB Output is correct
23 Correct 0 ms 4720 KB Output is correct
24 Correct 0 ms 4720 KB Output is correct
25 Correct 0 ms 5216 KB Output is correct
26 Correct 44 ms 7492 KB Output is correct
27 Correct 20 ms 5776 KB Output is correct
28 Correct 40 ms 7096 KB Output is correct
29 Correct 44 ms 7096 KB Output is correct
30 Correct 36 ms 7228 KB Output is correct
31 Correct 44 ms 7096 KB Output is correct
32 Correct 56 ms 7492 KB Output is correct
33 Correct 44 ms 7492 KB Output is correct
34 Correct 60 ms 7492 KB Output is correct