Submission #109970

# Submission time Handle Problem Language Result Execution time Memory
109970 2019-05-08T13:26:19 Z someone_aa Pipes (CEOI15_pipes) C++17
0 / 100
4057 ms 14056 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];

class dsu {
public:
    int uparent[maxn], usize[maxn];

    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[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;

    one.init();
    two.init();

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

        if(!one.connected(u, v)) {
            one.unite(u, v);
            two.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);
        }
    }

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

    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 2816 KB Wrong number of edges
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 3192 KB Wrong number of edges
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 316 ms 3064 KB Wrong number of edges
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 569 ms 3704 KB Wrong number of edges
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 923 ms 5380 KB Wrong number of edges
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1319 ms 10632 KB Wrong number of edges
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1985 ms 12024 KB Wrong number of edges
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2662 ms 14040 KB Wrong number of edges
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3633 ms 14056 KB Wrong number of edges
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4057 ms 13568 KB Wrong number of edges
2 Halted 0 ms 0 KB -