Submission #109979

# Submission time Handle Problem Language Result Execution time Memory
109979 2019-05-08T13:55:07 Z someone_aa Pipes (CEOI15_pipes) C++17
0 / 100
5000 ms 7212 KB
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
const int maxn = 100100;
vector<int>g[maxn];
int n, m;
int tin[maxn], low[maxn];

int uparent[maxn][2];
int usize[maxn][2];

int root(int x, int d) {
    while(x != uparent[x][d]) {
        x = uparent[x][d];
    }
    return x;
}

void unite(int x, int y, int d) {
    x = root(x, d);
    y = root(y, d);

    if(x == y) return;

    uparent[x][d] = y;
    usize[y][d] += usize[x][d];
}

int br;
bool visited[maxn];

set<pair<int,int> > result;

void dfs(int node, int p) {
    if(visited[node]) return;
    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]) {
                result.insert(mp(min(i, node), max(i, node)));
            }
        }
    }
}

int main() {
    cin>>n>>m;
    int u, v;

    for(int i=0;i<n;i++) {
        usize[i][0] = usize[i][1] = 1;
        uparent[i][0] = uparent[i][1] = i;
    }

    for(int i=0;i<m;i++) {
        cin>>u>>v;
        u--; v--;

        if(root(u, 1) == root(v, 1)) continue;

        if(root(u,0) != root(v,0)) {
            unite(u, v, 0);
            g[u].pb(v);
            g[v].pb(u);
        }
        else {
            unite(u, v, 1);
            g[u].pb(v);
            g[v].pb(u);
        }
    }

    memset(tin,-1,sizeof(tin));
    memset(low,-1,sizeof(low));

    for(int i=0;i<n;i++) {
        if(!visited[i]) {
            dfs(i, -1);
        }
    }

    for(auto i:result) {
        cout<<i.first+1<<" "<<i.second+1<<"\n";
    }

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 3456 KB Output is correct
2 Incorrect 5 ms 3456 KB Wrong number of edges
# Verdict Execution time Memory Grader output
1 Correct 29 ms 3960 KB Output is correct
2 Incorrect 16 ms 3840 KB Wrong number of edges
# Verdict Execution time Memory Grader output
1 Correct 1585 ms 3836 KB Output is correct
2 Incorrect 483 ms 3704 KB Wrong number of edges
# Verdict Execution time Memory Grader output
1 Execution timed out 5068 ms 3268 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5017 ms 4180 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5077 ms 6144 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5088 ms 6544 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5055 ms 7108 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5013 ms 7212 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5078 ms 6896 KB Time limit exceeded
2 Halted 0 ms 0 KB -