답안 #581721

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
581721 2022-06-23T04:52:30 Z 반딧불(#8365) 전압 (JOI14_voltage) C++14
10 / 100
1000 ms 14708 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int n, m;
vector<pair<int, int> > link[100002];
int ex[100002], ey[100002];
int ans;
int p;

bool visited[100002];
bool col[100002];
bool dfs(int x){
    visited[x] = 1;
    for(auto y: link[x]){
        int nc = !col[x];
        if(y.second == p) nc=!nc;
        if(visited[y.first]){
            if(col[y.first]!=nc) return false;
            continue;
        }
        col[y.first] = nc;
        if(!dfs(y.first)) return false;
    }
    return true;
}

int main(){
    scanf("%d %d", &n, &m);
    for(int i=1; i<=m; i++){
        int x, y;
        scanf("%d %d", &x, &y);
        link[x].push_back(make_pair(y, i));
        link[y].push_back(make_pair(x, i));
        ex[i] = x, ey[i] = y;
    }
    for(int i=1; i<=m; i++){
        p=i;
        memset(visited, 0, sizeof(visited));
        bool able=1;
        for(int j=1; j<=n; j++){
            if(visited[j]) continue;
            if(!dfs(j)){
                able=0;
                break;
            }
        }
        if(able) ans++;
    }
    printf("%d", ans);
}

Compilation message

voltage.cpp: In function 'int main()':
voltage.cpp:31:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |     scanf("%d %d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~
voltage.cpp:34:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |         scanf("%d %d", &x, &y);
      |         ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 2876 KB Output is correct
2 Correct 21 ms 2800 KB Output is correct
3 Correct 10 ms 2772 KB Output is correct
4 Correct 20 ms 2772 KB Output is correct
5 Correct 34 ms 2848 KB Output is correct
6 Correct 46 ms 2772 KB Output is correct
7 Correct 41 ms 2772 KB Output is correct
8 Correct 19 ms 2856 KB Output is correct
9 Correct 26 ms 2772 KB Output is correct
10 Correct 34 ms 2856 KB Output is correct
11 Correct 15 ms 2792 KB Output is correct
12 Correct 33 ms 2772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1083 ms 7512 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1078 ms 7492 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 31 ms 14708 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -