Submission #109986

# Submission time Handle Problem Language Result Execution time Memory
109986 2019-05-08T14:08:55 Z someone_aa Pipes (CEOI15_pipes) C++17
20 / 100
4479 ms 13912 KB
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
vector<int>g[100100];
int n, m;
int tin[100100], low[100100];
 
class dsu {
public:
    int uparent[100100], usize[100100];
 
    void init() {
        for(int i=0;i<=n;i++) {
            uparent[i] = i;
            usize[i] = 1;
        }
    }
    int uroot(int x) {
        while(x != uparent[x]) {
            x = uparent[x];
        }
        return x;
    }
    bool connected(int x, int y) {
        return uroot(x) == uroot(y);
    }
    void unite(int x, int y) {
        x = uroot(x);
        y = uroot(y);
 
        if(usize[x] > usize[y]) {
            uparent[y] = x;
            usize[x] += usize[y];
        }
        else {
            uparent[x] = y;
            usize[y] += usize[x];
        }
    }
}one, two;
 
int br;
bool visited[100100];
 
void dfs(int node, int p) {
    tin[node] = br++;
    low[node] = tin[node];
    visited[node] = true;
    for(int i:g[node]) {
        if(i == p) continue;
        if(visited[i]) {
            low[node] = min(low[node], tin[i]);
        }
        else {
            dfs(i, node);
            low[node] = min(low[node], low[i]);
            if(low[i] > tin[node]) {
                cout<<i<<" "<<node<<"\n";
            }
        }
    }
}
 
int main() {
    cin>>n>>m;
    int u, v;
 
    one.init();
    two.init();
 
    for(int i=0;i<m;i++) {
        cin>>u>>v;
 
        if(!one.connected(u, v)) {
            one.unite(u, v);
            g[u].pb(v);
            g[v].pb(u);
        }
        else {
            if(two.connected(u, v)) continue;
            two.unite(u, v);
            g[u].pb(v);
            g[v].pb(u);
        }
    }
 
    for(int i=1;i<=n;i++) {
        if(!visited[i]) {
            dfs(i, -1);
        }
    }
 
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2688 KB Output is correct
2 Incorrect 4 ms 2688 KB Wrong number of edges
# Verdict Execution time Memory Grader output
1 Correct 11 ms 3200 KB Output is correct
2 Incorrect 12 ms 2944 KB Wrong number of edges
# Verdict Execution time Memory Grader output
1 Correct 324 ms 3068 KB Output is correct
2 Incorrect 310 ms 2936 KB Wrong number of edges
# Verdict Execution time Memory Grader output
1 Incorrect 569 ms 3800 KB Wrong number of edges
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 960 ms 5348 KB Output is correct
2 Correct 858 ms 5176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1330 ms 10616 KB Output is correct
2 Incorrect 1083 ms 7672 KB Wrong number of edges
# Verdict Execution time Memory Grader output
1 Correct 2081 ms 11700 KB Output is correct
2 Incorrect 2134 ms 9216 KB Wrong number of edges
# Verdict Execution time Memory Grader output
1 Correct 2713 ms 13912 KB Output is correct
2 Incorrect 2640 ms 9836 KB Wrong number of edges
# Verdict Execution time Memory Grader output
1 Correct 3428 ms 13912 KB Output is correct
2 Incorrect 3299 ms 9832 KB Wrong number of edges
# Verdict Execution time Memory Grader output
1 Correct 4479 ms 13248 KB Output is correct
2 Correct 4001 ms 11000 KB Output is correct