Submission #1003177

# Submission time Handle Problem Language Result Execution time Memory
1003177 2024-06-20T07:18:15 Z Alihan_8 Pipes (CEOI15_pipes) C++17
40 / 100
731 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;
    Dsu(int m){
        fa.resize(m);
        for ( int i = 0; i < m; i++ ){
            fa[i] = i;
        }
    }
    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;
        return true;
    }
    bool same(int u, int v){
        return get(u) == get(v);
    }
};

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;

        bool flag = false;

        for ( auto &v: adj[u] ){
            if ( v == p && !flag ){
                flag = true;

                continue;
            }

            if ( !tin[v] ){
                dfs(dfs, v, u);

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

                if ( low[v] > tin[u] ){
                    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 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1112 KB Output is correct
2 Correct 3 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 58 ms 6228 KB Output is correct
2 Correct 57 ms 5716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 103 ms 10856 KB Output is correct
2 Correct 123 ms 11800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 171 ms 18516 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 272 ms 29780 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 380 ms 42396 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 500 ms 54736 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 607 ms 65536 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 731 ms 65536 KB Memory limit exceeded
2 Halted 0 ms 0 KB -