답안 #156331

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
156331 2019-10-05T07:12:06 Z Akashi Pipes (CEOI15_pipes) C++14
90 / 100
1804 ms 22244 KB
#include <bits/stdc++.h>
using namespace std;

struct dsu{
    int TT[100001];

    void init(int n){
        for(int i = 1; i <= n ; ++i) TT[i] = i;
    }

    void unite(int x, int y){TT[x] = y;}

    int find(int x){
        int R = x;
        while(R != TT[R]) R = TT[R];

        while(x != TT[x]){
            int aux = TT[x];
            TT[x] = R;
            x = aux;
        }

        return R;
    }

};

dsu A, B;
int n, m;
int low[100001], h[100001];
bool viz[100001];
vector <int> v[100001];

void tarjan(int nod, int papa = 0){
    viz[nod] = 1;
    int cnt = 0;
    for(auto it : v[nod]){
        if(papa == it){
            ++cnt;
            continue ;
        }

        if(!viz[it]){
            low[it] = h[nod] + 1; h[it] = h[nod] + 1;
            tarjan(it, nod);
            low[nod] = min(low[nod], low[it]);
            if(low[it] > h[nod]) printf("%d %d\n", it, nod);
        }
        else low[nod] = min(h[it], low[nod]);
    }
    if(cnt > 1) low[nod] = min(low[nod], h[nod] - 1);
}

int main()
{
    scanf("%d%d", &n, &m);

    A.init(n); B.init(n);

    int x, y;
    for(int i = 1; i <= m ; ++i){
        scanf("%d%d", &x, &y);
        if(A.find(x) != A.find(y)){
            v[x].push_back(y);
            v[y].push_back(x);
            A.unite(A.find(x), A.find(y));
        }
        else if(B.find(x) != B.find(y)){
            v[x].push_back(y);
            v[y].push_back(x);
            B.unite(B.find(x), B.find(y));
        }
    }

    for(int i = 1; i <= n ; ++i) if(!viz[i]) tarjan(i);

    return 0;
}

Compilation message

pipes.cpp: In function 'int main()':
pipes.cpp:56:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~
pipes.cpp:62:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &x, &y);
         ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 2680 KB Output is correct
2 Correct 4 ms 2680 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 3192 KB Output is correct
2 Correct 9 ms 2936 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 144 ms 3064 KB Output is correct
2 Correct 141 ms 2936 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 250 ms 3704 KB Output is correct
2 Correct 293 ms 3304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 457 ms 5148 KB Output is correct
2 Correct 355 ms 4896 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 614 ms 10036 KB Output is correct
2 Correct 520 ms 7288 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 896 ms 11056 KB Output is correct
2 Correct 845 ms 8660 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1194 ms 13136 KB Output is correct
2 Correct 1122 ms 9164 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1456 ms 13132 KB Output is correct
2 Correct 1431 ms 9056 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1804 ms 12616 KB Output is correct
2 Runtime error 1802 ms 22244 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)