답안 #3390

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
3390 2013-08-31T05:20:05 Z solveit Cactus? Not cactus? (kriii1_C) C++
0 / 1
76 ms 11828 KB
#include <iostream>
#include <string>
#include <math.h>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <set>
#include <vector>

using namespace std;

int N, M, visited[100005], cnt[100005];
vector<int> G[100005];

void dfs(int u, int p) {
    visited[u] = 1;
    for(int i = 0;i<G[u].size();i++) {
        int v = G[u][i];
        if(visited[v] && v != p)
            cnt[v]++;
        if(visited[v]) continue;
        dfs(v, u);
    }
}

int main() {
    scanf("%d %d",&N, &M);
    for(int i = 0;i<M;i++) {
        int u, v;
        scanf("%d %d",&u, &v);
        G[u].push_back(v);
        G[v].push_back(u);
    }
    dfs(1, -1);
    int ok = 1;
    for(int i = 1;i<=N;i++) {
        if(cnt[i] > 1)
            ok = 0;
    }
    if(ok)
        printf("Cactus\n");
    else
        printf("Not cactus\n");
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 4796 KB Output is correct
2 Correct 0 ms 4796 KB Output is correct
3 Correct 0 ms 4928 KB Output is correct
4 Correct 0 ms 4796 KB Output is correct
5 Correct 0 ms 4796 KB Output is correct
6 Correct 0 ms 4928 KB Output is correct
7 Correct 4 ms 4928 KB Output is correct
8 Correct 4 ms 4928 KB Output is correct
9 Correct 0 ms 4928 KB Output is correct
10 Correct 32 ms 7700 KB Output is correct
11 Correct 24 ms 7548 KB Output is correct
12 Correct 36 ms 8900 KB Output is correct
13 Correct 44 ms 8200 KB Output is correct
14 Correct 44 ms 8000 KB Output is correct
15 Correct 48 ms 9816 KB Output is correct
16 Correct 40 ms 8128 KB Output is correct
17 Correct 32 ms 8960 KB Output is correct
18 Correct 52 ms 11044 KB Output is correct
19 Correct 76 ms 11828 KB Output is correct
20 Correct 32 ms 8452 KB Output is correct
21 Correct 48 ms 8184 KB Output is correct
22 Correct 40 ms 10232 KB Output is correct
23 Correct 0 ms 4796 KB Output is correct
24 Correct 0 ms 4796 KB Output is correct
25 Incorrect 4 ms 5296 KB Output isn't correct
26 Halted 0 ms 0 KB -