Submission #673846

# Submission time Handle Problem Language Result Execution time Memory
673846 2022-12-22T09:21:48 Z benjaminkleyn Pipes (CEOI15_pipes) C++17
80 / 100
1033 ms 53100 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 = 100000;

int mem[2 * max_n];
int *e[2];

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

int n, m, timer = 0;
vector<int> g[max_n];
int edge_xor[2 * max_n], edge_cnt = 0;
int *ti, *lo;

void dfs(const int &u, const int &p)
{
    ti[u] = lo[u] = ++timer;
    for (const int &e : g[u])
        if (e != p)
        {
            int v = edge_xor[e] ^ u;
            if (ti[v])
                lo[u] = min(lo[u], ti[v]);
            else
            {
                dfs(v, e);
                lo[u] = min(lo[u], lo[v]);

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


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

    cin >> n >> m;

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

        
        if ((A = find(a, 0)) != (B = find(b, 0)))
        {
            if (e[0][A] > e[0][B]) swap(A, B);
            e[0][A] += e[0][B], e[0][B] = A;
        }
        else if ((A = find(a, 1)) != (B = find(b, 1)))
        {
            if (e[1][A] > e[1][B]) swap(A, B);
            e[1][A] += e[1][B], e[1][B] = A;
        }
        else
            continue;

        g[a].push_back(edge_cnt);
        g[b].push_back(edge_cnt);
        edge_xor[edge_cnt] = a ^ b;
        edge_cnt++;
    }

    ti = &mem[0];
    lo = &mem[max_n];

    for (int i = 0; i < n; i++)
        ti[i] = lo[i] = 0;

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

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 3 ms 2648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 3276 KB Output is correct
2 Correct 5 ms 3028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 90 ms 3740 KB Output is correct
2 Correct 92 ms 3660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 140 ms 4488 KB Output is correct
2 Correct 183 ms 3960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 246 ms 6092 KB Output is correct
2 Correct 196 ms 5428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 340 ms 10636 KB Output is correct
2 Correct 314 ms 7164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 481 ms 11940 KB Output is correct
2 Correct 514 ms 9288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 648 ms 14228 KB Output is correct
2 Correct 655 ms 9016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 877 ms 14488 KB Output is correct
2 Runtime error 848 ms 33468 KB Memory limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 946 ms 13696 KB Output is correct
2 Runtime error 1033 ms 53100 KB Memory limit exceeded
3 Halted 0 ms 0 KB -