답안 #25780

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
25780 2017-06-24T06:12:27 Z 시제연(#1082) 전압 (JOI14_voltage) C++
10 / 100
43 ms 7232 KB
#include <bits/stdc++.h>

using namespace std;

int n, m;
vector<int> lis[100100];
vector<int> id[100100];

int color[100100];
bool dfs(int here, int avoid, int col) {
    int i;
    color[here] = col;
    for (i=0;i<lis[here].size();i++) {
        int there = lis[here][i];
        if (id[here][i]==avoid) {
            if (color[there]) {
                if (color[there]!=color[here]) return false;
                continue;
            }
            if (!dfs(there,avoid,col)) return false;
            continue;
        }
        if (color[there]) {
            if (color[there]==color[here]) return false;
            continue;
        }
        if (!dfs(there,avoid,3-col)) return false;
    }
    return true;
}

int main() {
    int i, j;

    //freopen("input","r",stdin);

    scanf("%d%d",&n,&m);
    if (n>2000||m>3000) return 0;
    for (i=0;i<m;i++) {
        int a, b;
        scanf("%d%d",&a,&b);
        a--;b--;
        lis[a].push_back(b);
        id[a].push_back(i);
        lis[b].push_back(a);
        id[b].push_back(i);
    }
    int cnt = 0;
    for (i=0;i<m;i++) {
        for (j=0;j<n;j++) color[j] = 0;
        for (j=0;j<n;j++) {
            if (color[j]) continue;
            if (!dfs(j,i,1)) break;
        }
        if (j==n) cnt++;
    }
    printf("%d\n",cnt);

    return 0;
}

Compilation message

voltage.cpp: In function 'bool dfs(int, int, int)':
voltage.cpp:13:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (i=0;i<lis[here].size();i++) {
               ^
voltage.cpp: In function 'int main()':
voltage.cpp:37:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&n,&m);
                        ^
voltage.cpp:41:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d",&a,&b);
                            ^
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 7232 KB Output is correct
2 Correct 13 ms 7100 KB Output is correct
3 Correct 3 ms 7232 KB Output is correct
4 Correct 19 ms 7232 KB Output is correct
5 Correct 33 ms 7232 KB Output is correct
6 Correct 43 ms 7232 KB Output is correct
7 Correct 33 ms 7232 KB Output is correct
8 Correct 16 ms 7232 KB Output is correct
9 Correct 16 ms 7232 KB Output is correct
10 Correct 29 ms 7232 KB Output is correct
11 Correct 6 ms 7232 KB Output is correct
12 Correct 33 ms 7232 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 7100 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 7100 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 7100 KB Output isn't correct
2 Halted 0 ms 0 KB -