Submission #1003182

# Submission time Handle Problem Language Result Execution time Memory
1003182 2024-06-20T07:21:25 Z Alihan_8 Pipes (CEOI15_pipes) C++17
40 / 100
679 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);
    }
};

const int N = 1e5 + 1;

int low[N], tin[N];

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);
        }
    }

    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 2 ms 860 KB Output is correct
2 Correct 3 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 51 ms 6064 KB Output is correct
2 Correct 50 ms 5716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 86 ms 10484 KB Output is correct
2 Correct 108 ms 11620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 163 ms 17492 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 245 ms 26632 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 375 ms 38912 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 472 ms 50252 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 589 ms 61008 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 679 ms 65536 KB Memory limit exceeded
2 Halted 0 ms 0 KB -