# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
221658 | 2020-04-10T20:45:21 Z | Lawliet | Pipes (CEOI15_pipes) | C++17 | 5 ms | 512 KB |
#include <bits/stdc++.h> using namespace std; typedef pair<int,int> pii; const int LOG = 18; const int MAXN = 10; int n, m; int sz[MAXN]; int root[MAXN]; int prof[MAXN]; int dp[LOG][MAXN]; int lastNode[MAXN]; vector< int > adj[MAXN]; set< pii > bridges; void DFS(int cur, int p, int curRoot) { dp[0][cur] = p; root[cur] = curRoot; prof[cur] = prof[p] + 1; for(int k = 1 ; k < LOG ; k++) { int jump = dp[k - 1][cur]; dp[k][cur] = dp[k - 1][jump]; } for(int i = 0 ; i < adj[cur].size() ; i++) { int viz = adj[cur][i]; if( viz != p ) DFS( viz , cur , curRoot ); } } int getLastNode(int cur) { if( lastNode[cur] == cur ) return cur; return lastNode[cur] = getLastNode( lastNode[cur] ); } int LCA(int U, int V) { if( prof[U] < prof[V] ) swap( U , V ); int d = prof[U] - prof[V]; for(int k = 0 ; k < LOG ; k++) if( d & (1 << k) ) U = dp[k][U]; if( U == V ) return U; for(int k = LOG - 1 ; k >= 0 ; k--) { if( dp[k][U] != dp[k][V] ) { U = dp[k][U]; V = dp[k][V]; } } return dp[0][U]; } void mergePath(int U, int L) { U = getLastNode( U ); while( prof[U] > prof[L] ) { bridges.erase( { U , dp[0][U] } ); bridges.erase( { dp[0][U] , U } ); lastNode[U] = dp[0][U]; U = getLastNode( U ); } } void addEdge(int U, int V) { if( root[U] != root[V] ) { adj[U].push_back( V ); adj[V].push_back( U ); bridges.insert( { U , V } ); if( sz[ root[U] ] < sz[ root[V] ] ) swap( U , V ); sz[U] += sz[V]; DFS( V , U , root[U] ); return; } int L = LCA( U , V ); mergePath( U , L ); mergePath( V , L ); } int main() { scanf("%d %d",&n,&m); for(int i = 1 ; i <= n ; i++) { sz[i] = 1; root[i] = i; lastNode[i] = i; } for(int i = 1 ; i <= m ; i++) { int U, V; scanf("%d %d",&U,&V); addEdge( U , V ); } for(auto it = bridges.begin() ; it != bridges.end() ; it++) printf("%d %d\n",it->first,it->second); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 5 ms | 384 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 4 ms | 384 KB | Time limit exceeded (wall clock) |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 5 ms | 384 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 5 ms | 512 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 5 ms | 384 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 5 ms | 384 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 5 ms | 384 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 5 ms | 384 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 5 ms | 384 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 5 ms | 384 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |