Submission #656921

# Submission time Handle Problem Language Result Execution time Memory
656921 2022-11-08T14:01:32 Z benjaminkleyn Pipes (CEOI15_pipes) C++17
50 / 100
920 ms 50564 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<int> g[max_n];
int par[2][max_n];

int find(int u, int dsu)
{
    while (par[dsu][u] != u)
        par[dsu][u] = par[dsu][par[dsu][u]], u = par[dsu][u];
    return u;
}

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

void unite(int u, int v, int dsu)
{
    par[dsu][find(v, dsu)] = find(u, dsu);
}

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

                if (lo[v] > ti[u] && !(same_set(u, v, 0) && same_set(u, v, 1)))
                    cout << u << ' ' << v << '\n';
            }
        }
}


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

    cin >> n >> m;

    for (int i = 1; i <= n; i++)
        par[0][i] = par[1][i] = i;
    
    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);
        g[b].push_back(a);
    }

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

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 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 3156 KB Output is correct
2 Correct 4 ms 2900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 81 ms 3096 KB Output is correct
2 Correct 76 ms 2832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 131 ms 3776 KB Output is correct
2 Correct 150 ms 3256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 238 ms 5480 KB Output is correct
2 Correct 195 ms 5056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 301 ms 11272 KB Output is correct
2 Runtime error 281 ms 25364 KB Memory limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 463 ms 12568 KB Output is correct
2 Runtime error 491 ms 42700 KB Memory limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 618 ms 14952 KB Output is correct
2 Runtime error 613 ms 50564 KB Memory limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 769 ms 22456 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 920 ms 34704 KB Memory limit exceeded
2 Halted 0 ms 0 KB -