답안 #581936

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

using namespace std;

typedef long long ll;

int n, m;
vector<pair<int, int> > link[200002];
int ex[200002], ey[200002];
bool usedInTree[200002];

vector<int> remEdge;
int ans;

bool visited[200002];
bool col[200002];
bool isWrong[200002];
int in[200002], out[200002], inCnt;
int depth[200002];

void tree_dfs(int x){
    visited[x] = 1;
    in[x] = ++inCnt;
    for(auto y: link[x]){
        if(visited[y.first]) continue;
        usedInTree[y.second] = true;
        col[y.first] = !col[x];
        depth[y.first] = depth[x]+1;
        tree_dfs(y.first);
    }
    out[x] = inCnt;
}

int main(){
    scanf("%d %d", &n, &m);
    assert(m>=n);
    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<=n; i++){
        if(!visited[i]) tree_dfs(i);
    }
    for(int i=1; i<=m; i++) if(!usedInTree[i]) remEdge.push_back(i);
    for(int i=1; i<=n; i++) link[i].clear();
    for(int i=1; i<=m; i++){
        if(usedInTree[i]) link[ex[i]].push_back(make_pair(ey[i], i)), link[ey[i]].push_back(make_pair(ex[i], i));
        else{
            isWrong[i] = (col[ex[i]] == col[ey[i]]);
        }
    }
    if(count(isWrong+1, isWrong+n+1, true) == 1) ans++;

    for(int i=1; i<=m; i++){
        if(!usedInTree[i]) continue;
        int p = ex[i], x = ey[i];
        if(depth[p] > depth[x]) swap(x, p);

        bool bad = 0;
        for(auto e: remEdge){
            bool a = isWrong[e];
            bool b = (in[x] <= in[ex[e]] && in[ex[e]] <= out[x]) ^
                     (in[x] <= in[ey[e]] && in[ey[e]] <= out[x]);
            if(a!=b){
                bad=1;
                break;
            }
        }
        if(!bad) ans++;
    }
    printf("%d", ans);
}

Compilation message

voltage.cpp: In function 'int main()':
voltage.cpp:35:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |     scanf("%d %d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~
voltage.cpp:39:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |         scanf("%d %d", &x, &y);
      |         ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5076 KB Output is correct
2 Correct 3 ms 5076 KB Output is correct
3 Incorrect 3 ms 5076 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 11204 KB Output is correct
2 Correct 75 ms 14000 KB Output is correct
3 Correct 41 ms 11200 KB Output is correct
4 Correct 82 ms 15312 KB Output is correct
5 Correct 10 ms 5844 KB Output is correct
6 Correct 85 ms 12932 KB Output is correct
7 Correct 77 ms 16556 KB Output is correct
8 Correct 66 ms 16648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 7 ms 9940 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1070 ms 13636 KB Time limit exceeded
2 Halted 0 ms 0 KB -