Submission #109980

# Submission time Handle Problem Language Result Execution time Memory
109980 2019-05-08T13:59:50 Z someone_aa Pipes (CEOI15_pipes) C++17
0 / 100
5000 ms 7228 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;
        else 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 4 ms 3456 KB Output is correct
2 Incorrect 4 ms 3456 KB Wrong number of edges
# Verdict Execution time Memory Grader output
1 Correct 28 ms 3960 KB Output is correct
2 Incorrect 16 ms 3840 KB Wrong number of edges
# Verdict Execution time Memory Grader output
1 Correct 1624 ms 3832 KB Output is correct
2 Incorrect 487 ms 3680 KB Wrong number of edges
# Verdict Execution time Memory Grader output
1 Execution timed out 5032 ms 3260 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5091 ms 4176 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5056 ms 6004 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5011 ms 6404 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5058 ms 7184 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5086 ms 7228 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 5078 ms 6944 KB Time limit exceeded
2 Halted 0 ms 0 KB -