답안 #100623

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
100623 2019-03-12T21:24:49 Z doowey Pipes (CEOI15_pipes) C++14
0 / 100
1453 ms 29088 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int N = (int)1e5+1;
int n1[N];
int n2[N];

int fin1(int x){
    if(n1[x]==x)
        return x;
    return n1[x]=fin1(n1[x]);
}

int fin2(int x){
    if(n2[x]==x)
        return x;
    return n2[x]=fin2(n2[x]);
}

bool merge1(int a, int b){
    a=fin1(a);
    b=fin1(b);
    if(a==b) return false;
    n1[a]=b;
    return true;
}

bool merge2(int a,int b){
    a=fin2(a);
    b=fin2(b);
    if(a==b) return false;
    n2[a]=b;
    return true;
}

set <int> T[N];
int tin[N];
int low[N];

int timer;


void dfs(int u, int par){
    tin[u] = ++ timer ;
    low[u] = tin[u];
    int x;
    for(auto x : T[u]){
        if(tin[x] != 0){
            low[u] = min(low[u], tin[x]);
        }
        else{
            dfs(x,u);
            low[u] = min(low[u], low[x]);
            if(tin[u]<low[x] && fin2(u) != fin2(x)){
                cout << u << " " << x << "\n";
            }
        }
    }
}

int main(){
    fastIO;
    int n, m;
    cin >> n >> m;
    for(int i = 1; i <= n; i ++ ){
        n1[i]=i;
        n2[i]=i;
    }
    int u, v;
    for(int i = 0 ; i < m ; i ++ ){
        cin >> u >> v;
        if(merge1(u,v)){
            T[u].insert(v);
            T[v].insert(u);
        }
        else if(merge2(u,v)){
            T[u].insert(v);
            T[v].insert(u);
        }

    }
    for(int i = 1; i <= n; i ++ )if(tin[i] == 0) dfs(i,-1);
    return 0;
}

Compilation message

pipes.cpp: In function 'void dfs(int, int)':
pipes.cpp:55:9: warning: unused variable 'x' [-Wunused-variable]
     int x;
         ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 4992 KB Wrong number of edges
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 12 ms 6144 KB Wrong number of edges
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 107 ms 5916 KB Output is correct
2 Incorrect 103 ms 5752 KB Wrong number of edges
# 결과 실행 시간 메모리 Grader output
1 Correct 177 ms 7504 KB Output is correct
2 Incorrect 198 ms 7032 KB Wrong number of edges
# 결과 실행 시간 메모리 Grader output
1 Correct 324 ms 10848 KB Output is correct
2 Incorrect 269 ms 10204 KB Wrong number of edges
# 결과 실행 시간 메모리 Grader output
1 Runtime error 547 ms 21892 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 807 ms 24448 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1025 ms 29080 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1219 ms 29088 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1453 ms 27996 KB Memory limit exceeded (if you are sure your verdict is not MLE, please contact us)
2 Halted 0 ms 0 KB -