Submission #444589

# Submission time Handle Problem Language Result Execution time Memory
444589 2021-07-14T10:00:31 Z prvocislo Pipes (CEOI15_pipes) C++17
90 / 100
1371 ms 19288 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;
    bool seen = false;
    for (int v : g[u])
    {
        if (v == p && !seen) seen = true;
        else if (vis[v]) low[u] = min(low[u], tin[v]);
        else
        {
            dfs(v, u);
            low[u] = min(low[u], low[v]);
        }
    }
    if (p != -1 && tin[u] == low[u])
         bridge(u, p);
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0); 
    cin >> n >> m;
    int cnt = 0;
    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))
        {cnt++;
            //cout << "edge " << a << " " << b << endl;
            g[a].push_back(b), g[b].push_back(a);
        }
    }
    //cout << cnt << "\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 Correct 2 ms 3384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 3788 KB Output is correct
2 Correct 6 ms 3696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 120 ms 3708 KB Output is correct
2 Correct 116 ms 3584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 215 ms 4332 KB Output is correct
2 Correct 250 ms 15332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 357 ms 5804 KB Output is correct
2 Runtime error 314 ms 19288 KB Memory limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 461 ms 10424 KB Output is correct
2 Correct 405 ms 7528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 740 ms 11424 KB Output is correct
2 Correct 701 ms 8904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 936 ms 13324 KB Output is correct
2 Correct 871 ms 9256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1160 ms 13328 KB Output is correct
2 Correct 1104 ms 11236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1371 ms 12824 KB Output is correct
2 Correct 1291 ms 10532 KB Output is correct