답안 #48287

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
48287 2018-05-11T12:02:22 Z choikiwon 전압 (JOI14_voltage) C++17
0 / 100
82 ms 21400 KB
#include<bits/stdc++.h>
using namespace std;

const int MN = 100010;

int N, M;
vector<int> adj[MN], U, V;
int tin[MN], timer, cnt;
priority_queue<int> pq1, pq2;
int ans;

void dfs0(int u, int fe) {
    tin[u] = timer++;
    for(int i = 0; i < adj[u].size(); i++) {
        int e = adj[u][i];
        int v = U[e] + V[e] - u;
        if(e == fe) continue;
        if(tin[v] == -1) {
            dfs0(v, e);
        }
        else if(tin[v] < tin[u]) {
            if(tin[v] % 2 == tin[u] % 2) cnt++;
        }
    }
}

void dfs1(int u, int fe) {
    tin[u] = timer++;
    for(int i = 0; i < adj[u].size(); i++) {
        int e = adj[u][i];
        int v = U[e] + V[e] - u;
        if(e == fe) continue;
        if(tin[v] == -1) {
            dfs1(v, e);
        }
    }
    for(int i = 0; i < adj[u].size(); i++) {
        int e = adj[u][i];
        int v = U[e] + V[e] - u;
        if(e == fe) continue;
        if(tin[v] != -1 && tin[v] < tin[u]) {
            if(tin[v] % 2 == tin[u] % 2) pq1.push(tin[v]);
            else pq2.push(tin[v]);
        }
    }
    while(!pq1.empty() && pq1.top() == tin[u]) pq1.pop();
    while(!pq2.empty() && pq2.top() == tin[u]) pq2.pop();
    if(u && (int)pq1.size() == cnt && !pq2.size()) ans++;
}

int main() {
    scanf("%d %d", &N, &M);

    for(int i = 0; i < M; i++) {
        int u, v; scanf("%d %d", &u, &v);
        u--; v--;

        adj[u].push_back(U.size());
        adj[v].push_back(U.size());
        U.push_back(u);
        V.push_back(v);
    }

    memset(tin, -1, sizeof(tin));
    dfs0(0, -1);

    memset(tin, -1, sizeof(tin));
    dfs1(0, -1);

    if(cnt == 1) ans++;
    printf("%d", ans);
}

Compilation message

voltage.cpp: In function 'void dfs0(int, int)':
voltage.cpp:14:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < adj[u].size(); i++) {
                    ~~^~~~~~~~~~~~~~~
voltage.cpp: In function 'void dfs1(int, int)':
voltage.cpp:29:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < adj[u].size(); i++) {
                    ~~^~~~~~~~~~~~~~~
voltage.cpp:37:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < adj[u].size(); i++) {
                    ~~^~~~~~~~~~~~~~~
voltage.cpp: In function 'int main()':
voltage.cpp:52:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &N, &M);
     ~~~~~^~~~~~~~~~~~~~~~~
voltage.cpp:55:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         int u, v; scanf("%d %d", &u, &v);
                   ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 3292 KB Output is correct
2 Correct 4 ms 3328 KB Output is correct
3 Correct 5 ms 3596 KB Output is correct
4 Correct 4 ms 3596 KB Output is correct
5 Incorrect 5 ms 3608 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 62 ms 9136 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 10056 KB Output is correct
2 Correct 52 ms 15600 KB Output is correct
3 Correct 52 ms 16664 KB Output is correct
4 Incorrect 4 ms 16664 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 72 ms 16664 KB Output is correct
2 Correct 82 ms 21400 KB Output is correct
3 Incorrect 4 ms 21400 KB Output isn't correct
4 Halted 0 ms 0 KB -