Submission #48288

# Submission time Handle Problem Language Result Execution time Memory
48288 2018-05-11T12:06:57 Z choikiwon 전압 (JOI14_voltage) C++17
0 / 100
86 ms 12732 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));
    for(int i = 0; i < N; i++) if(tin[i] == -1) {
        dfs0(i, -1);
    }

    memset(tin, -1, sizeof(tin));
    for(int i = 0; i < N; i++) if(tin[i] == -1) {
        dfs1(i, -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);
                   ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 3064 KB Output is correct
2 Incorrect 4 ms 3172 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 61 ms 7428 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 35 ms 7428 KB Output is correct
2 Correct 54 ms 11956 KB Output is correct
3 Correct 49 ms 11956 KB Output is correct
4 Incorrect 4 ms 11956 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 77 ms 11956 KB Output is correct
2 Correct 86 ms 12732 KB Output is correct
3 Incorrect 5 ms 12732 KB Output isn't correct
4 Halted 0 ms 0 KB -