Submission #1003149

# Submission time Handle Problem Language Result Execution time Memory
1003149 2024-06-20T06:52:08 Z Alihan_8 Pipes (CEOI15_pipes) C++17
0 / 100
739 ms 65536 KB
#include <bits/stdc++.h>

using namespace std;

#define all(x) x.begin(), x.end()
#define ar array
#define pb push_back
#define ln '\n'
//#define int long long

using i64 = long long;

template <class F, class _S>
bool chmin(F &u, const _S &v){
    bool flag = false;
    if ( u > v ){
        u = v; flag |= true;
    }
    return flag;
}

template <class F, class _S>
bool chmax(F &u, const _S &v){
    bool flag = false;
    if ( u < v ){
        u = v; flag |= true;
    }
    return flag;
}

struct Dsu{
    // 0 - indexed
    vector <int> fa, sz;
    Dsu(int m){
        fa.resize(m);
        sz.resize(m);
        for ( int i = 0; i < m; i++ ){
            fa[i] = i; sz[i] = 1;
        }
    }
    int get(int x){
        return (x == fa[x] ? x : fa[x] = get(fa[x]));
    }
    bool merge(int u, int v){
        u = get(u), v = get(v);
        if ( u == v ){
            return false;
        }
        fa[v] = u;
        sz[u] += sz[v];
        return true;
    }
    bool same(int u, int v){
        return get(u) == get(v);
    }
    int size(int u){ return sz[get(u)]; }
};

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, m; cin >> n >> m;

    vector <vector<int>> adj(n);


    Dsu ds1(n), ds2(n);

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

        --u, --v;

        if ( ds1.merge(u, v) || ds2.merge(u, v) ){
            adj[u].pb(v);
            adj[v].pb(u);
        }
    }

    vector <int> tin(n), low(n);

    int ct = 0;

    auto dfs = [&](auto dfs, int u, int p) -> void{
        tin[u] = low[u] = ++ct;

        for ( auto &v: adj[u] ){
            if ( v != p ){
                if ( !tin[v] ){
                    dfs(dfs, v, u);

                    chmin(low[u], low[v]);

                    if ( tin[u] < low[v] ){
                        cout << u + 1 << ' ' << v + 1 << ln;
                    }
                } else{
                    chmin(low[u], tin[v]);
                }
            }
        }
    };

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

    cout << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 0 ms 348 KB Wrong number of edges
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1112 KB Output is correct
2 Incorrect 3 ms 860 KB Wrong number of edges
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 58 ms 6352 KB Output is correct
2 Incorrect 60 ms 5968 KB Wrong number of edges
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 105 ms 11580 KB Wrong number of edges
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 166 ms 20308 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 236 ms 32608 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 395 ms 46676 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 495 ms 60532 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 597 ms 65536 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 739 ms 65536 KB Memory limit exceeded
2 Halted 0 ms 0 KB -