# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1035131 | 2024-07-26T05:08:14 Z | vjudge1 | Pipes (CEOI15_pipes) | C++17 | 674 ms | 65536 KB |
#include <bits/stdc++.h> #define ll long long using namespace std; const int N = 1e5; vector < int > adj[N + 2]; struct dsu{ int par[N + 2]; int find_par(const int &u){ if(par[u] < 0)return u; par[u] = find_par(par[u]); return par[u]; } bool union_set(int u , int v){ u = find_par(u); v = find_par(v); if(u != v){ if(par[u] > par[v])swap(u , v); par[u] += par[v]; par[v] = u; return true; } return false; } } par1 , par2; int timer = 0; int n , m; void dfs(int c, int depth, int par){ par1.par[c] = depth; par2.par[c] = par1.par[c]; int op = par; for (int i : adj[c]){ if (i == par){par = -1; continue;} if (par1.par[i] != -1){ par2.par[c] = min( par2.par[c] ,par1.par[i]); continue;} dfs(i,depth+1,c); par2.par[c] = min(par2.par[c] , par2.par[i]); } if (par2.par[c] >= depth && op != -1) cout << c << " " << op << '\n'; } void solve() { cin >> n >> m; for(int i = 1; i <= n; i++){ par1.par[i] = par2.par[i] = -1; } for(int i = 1; i <= m ;i ++){ int u , v; cin >> u >> v; if(par1.union_set(u , v)){ adj[u].push_back(v); adj[v].push_back(u); // cout << u << ' ' << v<< '\n'; } else if(par2.union_set(u , v)){ adj[u].push_back(v); adj[v].push_back(u); // cout << u << ' '<< v << '\n'; } } for(int i = 1; i <= n ; i ++){ par1.par[i] = par2.par[i] = -1; } for(int i = 1; i <= n ; i++){ if(par1.par[i] == -1)dfs(i , 0 , -1); } } signed main() { ios::sync_with_stdio(0), cin.tie(0); #define _ "maxseq." if (fopen(_ "inp", "r")) { freopen(_ "inp", "r", stdin); freopen(_ "out", "w", stdout); } solve(); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 2648 KB | Output is correct |
2 | Correct | 1 ms | 2652 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 3164 KB | Output is correct |
2 | Correct | 3 ms | 2908 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 58 ms | 7584 KB | Output is correct |
2 | Correct | 63 ms | 7252 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 104 ms | 11476 KB | Output is correct |
2 | Correct | 119 ms | 12240 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 178 ms | 17900 KB | Memory limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 227 ms | 25996 KB | Memory limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 370 ms | 36792 KB | Memory limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 460 ms | 46568 KB | Memory limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 588 ms | 55380 KB | Memory limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 674 ms | 65536 KB | Memory limit exceeded |
2 | Halted | 0 ms | 0 KB | - |