답안 #581943

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
581943 2022-06-23T08:27:39 Z 반딧불(#8365) 전압 (JOI14_voltage) C++14
55 / 100
1000 ms 16612 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);
    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+m+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:38:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |         scanf("%d %d", &x, &y);
      |         ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 5076 KB Output is correct
2 Correct 3 ms 5076 KB Output is correct
3 Correct 3 ms 5076 KB Output is correct
4 Correct 3 ms 5076 KB Output is correct
5 Correct 5 ms 5076 KB Output is correct
6 Correct 6 ms 5076 KB Output is correct
7 Correct 5 ms 5184 KB Output is correct
8 Correct 4 ms 5076 KB Output is correct
9 Correct 6 ms 5076 KB Output is correct
10 Correct 4 ms 5076 KB Output is correct
11 Correct 3 ms 5076 KB Output is correct
12 Correct 4 ms 5076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 50 ms 11184 KB Output is correct
2 Correct 81 ms 13944 KB Output is correct
3 Correct 43 ms 11084 KB Output is correct
4 Correct 65 ms 15288 KB Output is correct
5 Correct 10 ms 5844 KB Output is correct
6 Correct 75 ms 12876 KB Output is correct
7 Correct 78 ms 16588 KB Output is correct
8 Correct 67 ms 16576 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 11140 KB Output is correct
2 Correct 42 ms 16588 KB Output is correct
3 Correct 58 ms 16612 KB Output is correct
4 Correct 3 ms 4948 KB Output is correct
5 Correct 70 ms 12756 KB Output is correct
6 Correct 69 ms 10988 KB Output is correct
7 Correct 116 ms 13772 KB Output is correct
8 Correct 84 ms 14668 KB Output is correct
9 Correct 92 ms 14724 KB Output is correct
10 Correct 114 ms 13360 KB Output is correct
11 Correct 67 ms 11132 KB Output is correct
12 Correct 92 ms 12620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1081 ms 13664 KB Time limit exceeded
2 Halted 0 ms 0 KB -