Submission #97600

# Submission time Handle Problem Language Result Execution time Memory
97600 2019-02-17T12:19:11 Z dalgerok Pipes (CEOI15_pipes) C++14
100 / 100
1286 ms 15128 KB
#include<bits/stdc++.h>
using namespace std;


const int N = 1e5 + 5;



int n, m;
int p[2][N];
int tin[N], fup[N], timer;
vector < pair < int, int > > g[N];

int dsu_get(int x, int v){
    return p[x][v] == v ? v : p[x][v] = dsu_get(x, p[x][v]);
}

void dfs(int v, int pr = 0){
    tin[v] = fup[v] = ++timer;
    for(int i = 0; i < (int)g[v].size(); i++){
        int to = g[v][i].first,
            ind = g[v][i].second;
        if(ind == pr){
            continue;
        }
        if(!tin[to]){
            dfs(to, ind);
            if(fup[to] > tin[v]){
                cout << v << " " << to << "\n";
            }
            fup[v] = min(fup[v], fup[to]);
        }
        else{
            fup[v] = min(fup[v], tin[to]);
        }
    }
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin >> n >> m;
    for(int i = 1; i <= n; i++){
        p[0][i] = p[1][i] = i;
    }
    for(int i = 1; i <= m; i++){
        int x, y;
        cin >> x >> y;
        if(dsu_get(0, x) == dsu_get(0, y)){
            if(dsu_get(1, x) == dsu_get(1, y)){
                continue;
            }
            p[1][dsu_get(1, x)] = dsu_get(1, y);
        }
        else{
            p[0][dsu_get(0, x)] = dsu_get(0, y);
        }
        g[x].push_back(make_pair(y, i));
        g[y].push_back(make_pair(x, i));
    }
    for(int i = 1; i <= n; i++){
        if(!tin[i]){
            dfs(i);
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2688 KB Output is correct
2 Correct 4 ms 2688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 3328 KB Output is correct
2 Correct 8 ms 3072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 96 ms 3192 KB Output is correct
2 Correct 95 ms 2944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 163 ms 3944 KB Output is correct
2 Correct 198 ms 3576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 300 ms 5640 KB Output is correct
2 Correct 256 ms 5148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 448 ms 11336 KB Output is correct
2 Correct 528 ms 8516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 679 ms 12712 KB Output is correct
2 Correct 637 ms 9460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 914 ms 15128 KB Output is correct
2 Correct 858 ms 11060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1038 ms 15000 KB Output is correct
2 Correct 1037 ms 11052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1286 ms 14400 KB Output is correct
2 Correct 1207 ms 11036 KB Output is correct