Submission #804597

# Submission time Handle Problem Language Result Execution time Memory
804597 2023-08-03T10:05:12 Z Hanksburger Pipes (CEOI15_pipes) C++17
90 / 100
797 ms 23268 KB
#include <bits/stdc++.h>
using namespace std;
vector<int> adj[100005];
int par[100005][2], t;
int findPar(int u, int x)
{
    return (par[u][x]==u?u:par[u][x]=findPar(par[u][x], x));
}
void dfs(int u, int p)
{
    par[u][0]=par[u][1]=(++t);
    int pass=1;
    for (int v:adj[u])
    {
        if (v==p && pass)
        {
            pass=0;
            continue;
        }
        if (par[v][0])
            par[u][1]=min(par[u][1], par[v][0]);
        else
        {
            dfs(v, u);
            par[u][1]=min(par[u][1], par[v][1]);
            if (par[v][1]>=par[v][0])
                cout << u << ' ' << v << '\n';
        }
    }
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, m;
    cin >> n >> m;
    for (int i=1; i<=n; i++)
        par[i][0]=par[i][1]=i;
    for (int i=1; i<=m; i++)
    {
        int u, v, U, V;
        cin >> u >> v;
        if (findPar(u, 0)!=findPar(v, 0))
        {
            par[par[u][0]][0]=par[v][0];
            adj[u].push_back(v);
            adj[v].push_back(u);
        }
        else if (findPar(u, 1)!=findPar(v, 1))
        {
            par[par[u][1]][1]=par[v][1];
            adj[u].push_back(v);
            adj[v].push_back(u);
        }
    }
    for (int i=1; i<=n; i++)
        par[i][0]=par[i][1]=0;
    for (int i=1; i<=n; i++)
        if (!par[i][0])
            dfs(i, 0);
}

Compilation message

pipes.cpp: In function 'int main()':
pipes.cpp:42:19: warning: unused variable 'U' [-Wunused-variable]
   42 |         int u, v, U, V;
      |                   ^
pipes.cpp:42:22: warning: unused variable 'V' [-Wunused-variable]
   42 |         int u, v, U, V;
      |                      ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 3284 KB Output is correct
2 Correct 5 ms 2944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 65 ms 3216 KB Output is correct
2 Correct 66 ms 3072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 122 ms 4016 KB Output is correct
2 Correct 132 ms 3360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 201 ms 5588 KB Output is correct
2 Correct 157 ms 4996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 260 ms 10672 KB Output is correct
2 Correct 243 ms 6632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 389 ms 12056 KB Output is correct
2 Correct 375 ms 8684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 510 ms 14264 KB Output is correct
2 Correct 508 ms 8368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 635 ms 14608 KB Output is correct
2 Correct 642 ms 8368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 797 ms 13840 KB Output is correct
2 Runtime error 762 ms 23268 KB Memory limit exceeded
3 Halted 0 ms 0 KB -