Submission #444581

# Submission time Handle Problem Language Result Execution time Memory
444581 2021-07-14T09:35:40 Z prvocislo Pipes (CEOI15_pipes) C++17
0 / 100
1388 ms 25132 KB
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

const int maxn = 1e5 + 5;
struct dsu
{
    int p[maxn];
    int root(int r) { return r == p[r] ? r : p[r] = root(p[r]); }
    bool merge(int a, int b)
    {
        a = root(a), b = root(b);
        if (a == b) return false;
        p[a] = b;
        return true;
    }
    dsu() { for (int i = 0; i < maxn; i++) p[i] = i; }
} d[2];
int vis[maxn], tin[maxn], low[maxn], n, m, timer = 0;
vector<int> g[maxn];
void bridge(int a, int b) { cout << a+1 << " " << b+1 << "\n"; }
void dfs(int u, int p)
{
    low[u] = tin[u] = timer++, vis[u] = true;
    for (int v : g[u])
    {
        if (v != p && vis[v]) low[u] = min(low[u], tin[v]);
        else if (v != p)
        {
            dfs(v, u);
            low[u] = min(low[u], low[v]);
        }
    }
    if (p != -1 && tin[p] < low[u]) bridge(u, p);
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0); 
    cin >> n >> m;
    for (int i = 0, a, b; i < m; i++)
    {
        cin >> a >> b; a--, b--;
        if (d[0].merge(a, b) || d[1].merge(a, b))
        {
            //cout << "edge " << a << " " << b << endl;
            g[a].push_back(b), g[b].push_back(a);
        }
    }
    //cout << "bridges:\n";
    for (int i = 0; i < n; i++) if (!vis[i]) dfs(i, -1);
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3404 KB Output is correct
2 Incorrect 3 ms 3404 KB Wrong number of edges
# Verdict Execution time Memory Grader output
1 Correct 6 ms 3916 KB Output is correct
2 Incorrect 6 ms 3724 KB Wrong number of edges
# Verdict Execution time Memory Grader output
1 Correct 125 ms 9192 KB Output is correct
2 Incorrect 127 ms 8948 KB Wrong number of edges
# Verdict Execution time Memory Grader output
1 Incorrect 208 ms 13980 KB Wrong number of edges
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 340 ms 21944 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 477 ms 10952 KB Output is correct
2 Incorrect 401 ms 8124 KB Wrong number of edges
# Verdict Execution time Memory Grader output
1 Correct 771 ms 12212 KB Output is correct
2 Incorrect 662 ms 9760 KB Wrong number of edges
# Verdict Execution time Memory Grader output
1 Correct 957 ms 14516 KB Output is correct
2 Incorrect 873 ms 10440 KB Wrong number of edges
# Verdict Execution time Memory Grader output
1 Runtime error 1206 ms 23480 KB Memory limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1388 ms 14568 KB Output is correct
2 Runtime error 1325 ms 25132 KB Memory limit exceeded