Submission #658132

# Submission time Handle Problem Language Result Execution time Memory
658132 2022-11-12T09:05:13 Z FatihSolak Pipes (CEOI15_pipes) C++17
0 / 100
989 ms 33732 KB
#include <bits/stdc++.h>
#define N 200005
using namespace std;
struct DSU{
    vector<int> par;
    void init(int n){
        par.assign(n+1,0);
        for(int i = 1;i<=n;i++){
            par[i] = i;
        }
    }
    int find(int a){
        if(a == par[a])return a;
        return par[a] = find(par[a]);
    }
    bool merge(int a,int b){
        a = find(a);
        b = find(b);
        if(a == b)
            return 0;
        par[a] = b;
        return 1;
    }
};
int dep[N];
int mini[N];
bool vis[N];
vector<int> adj[N];
void dfs(int v,int par){
    vis[v] = 1;
    mini[v] = dep[v];
    for(auto u:adj[v]){
        if(u == par)continue;
        if(!vis[u]){
            dep[u] = dep[v] + 1;
            dfs(u,v);
            mini[v] = min(mini[v],mini[u]);
        }
        else{
            mini[v] = min(mini[v],dep[u]);
        }
    }
    if(par != 0 && dep[v] == mini[v]){
        cout << par << ' ' << v << '\n';
    }
}
void solve(){
    int n,m;
    cin >> n >> m;
    DSU d1,d2;
    d1.init(n);
    d2.init(n);
    for(int i = 1;i<=m;i++){
        int a,b;
        cin >> a >> b;
        if(d1.merge(a,b)){
            adj[a].push_back(b);
            adj[b].push_back(a);
        }
        else if(d2.merge(a,b)){
            adj[a].push_back(b);
            adj[b].push_back(a);
        }
    }
    for(int i = 1;i<=n;i++){
        if(!vis[i])
            dfs(i,0);
    }

}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    #ifdef Local
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
    #endif
    int t=1;
    //cin>>t;
    while(t--){
        solve();
    }
    #ifdef Local
    cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
    #endif
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4960 KB Output is correct
2 Incorrect 3 ms 5032 KB Wrong number of edges
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5588 KB Output is correct
2 Incorrect 5 ms 5344 KB Wrong number of edges
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 86 ms 10804 KB Output is correct
2 Incorrect 85 ms 10536 KB Wrong number of edges
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 162 ms 15712 KB Wrong number of edges
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 248 ms 23800 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 348 ms 33732 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 517 ms 16076 KB Output is correct
2 Incorrect 451 ms 13260 KB Wrong number of edges
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 650 ms 19368 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 806 ms 27628 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 989 ms 20768 KB Memory limit exceeded
2 Halted 0 ms 0 KB -