Submission #673838

# Submission time Handle Problem Language Result Execution time Memory
673838 2022-12-22T09:15:22 Z benjaminkleyn Pipes (CEOI15_pipes) C++17
40 / 100
1031 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 = 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));
}

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

bool unite(int u, int v, const 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 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; i < m; i++)
    {
        cin >> a >> b;
        a--, b--;

        if (!unite(a, b, 0) && !unite(a, b, 1))
            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 2 ms 2684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 3212 KB Output is correct
2 Correct 5 ms 2996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 94 ms 8500 KB Output is correct
2 Correct 93 ms 8360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 157 ms 13300 KB Output is correct
2 Correct 178 ms 14556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 272 ms 21548 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 357 ms 31312 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 545 ms 45228 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 741 ms 57744 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 854 ms 65536 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1031 ms 65536 KB Memory limit exceeded
2 Halted 0 ms 0 KB -