Submission #656919

# Submission time Handle Problem Language Result Execution time Memory
656919 2022-11-08T13:49:31 Z benjaminkleyn Pipes (CEOI15_pipes) C++17
40 / 100
1032 ms 65536 KB
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const int max_n = 100001;

int n, m, ti[max_n] = {0}, lo[max_n], timer = 0;
vector<pair<int,int>> g[max_n];

void dfs(int u, int p = -1)
{
    ti[u] = lo[u] = ++timer;
    for (auto [v, id] : g[u])
        if (id != p)
        {
            if (ti[v])
                lo[u] = min(lo[u], ti[v]);
            else
            {
                dfs(v, id);
                lo[u] = min(lo[u], lo[v]);

                if (lo[v] > ti[u])
                    cout << u << ' ' << v << '\n';
            }
        }
}

int e[2][max_n];

int find(int u, int dsu)
{
    return (e[dsu][u] < 0 ? u : (e[dsu][u] = find(e[dsu][u], dsu)));
}

bool same_set(int u, int v, int dsu)
{
    return find(u, dsu) == find(v, dsu);
}

bool unite(int u, int v, int dsu)
{
    u = find(u, dsu), v = find(v, dsu);
    if (u == v)
        return false;
    if (e[dsu][u] > e[dsu][v]) swap(u, v);
    e[dsu][u] += e[dsu][v];
    e[dsu][v] = u;
    return true;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n >> m;

    for (int i = 1; i <= n; i++)
        e[0][i] = e[1][i] = -1;
    
    for (int i = 0, a ,b; i < m; i++)
    {
        cin >> a >> b;

        if (!same_set(a, b, 0))
            unite(a, b, 0);
        else if (!same_set(a, b, 1))
            unite(a, b, 1);
        else continue;

        g[a].push_back({b, i});
        g[b].push_back({a, i});
    }

    for (int i = 1; i <= n; i++)
        if (!ti[i])
            dfs(i);

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 3284 KB Output is correct
2 Correct 5 ms 3028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 80 ms 3192 KB Output is correct
2 Correct 80 ms 8292 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 139 ms 4120 KB Output is correct
2 Correct 162 ms 14840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 222 ms 6216 KB Output is correct
2 Runtime error 200 ms 19412 KB Memory limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 326 ms 22152 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 492 ms 48124 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 689 ms 61588 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 835 ms 65536 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1032 ms 65536 KB Memory limit exceeded
2 Halted 0 ms 0 KB -