# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
221661 | 2020-04-10T20:50:15 Z | Lawliet | Pipes (CEOI15_pipes) | C++17 | 5 ms | 512 KB |
#include <bits/stdc++.h> using namespace std; typedef pair<short int,short int> pii; const short int LOG = 8; const short int MAXN = 101; short int n, m; short int sz[MAXN]; short int root[MAXN]; short int prof[MAXN]; short int dp[LOG][MAXN]; short int lastNode[MAXN]; vector< short int > adj[MAXN]; set< pii > bridges; void DFS(short int cur, short int p, short int curRoot) { dp[0][cur] = p; root[cur] = curRoot; prof[cur] = prof[p] + 1; for(short int k = 1 ; k < LOG ; k++) { short int jump = dp[k - 1][cur]; dp[k][cur] = dp[k - 1][jump]; } for(short int i = 0 ; i < adj[cur].size() ; i++) { short int viz = adj[cur][i]; if( viz != p ) DFS( viz , cur , curRoot ); } } short int getLastNode(short int cur) { if( lastNode[cur] == cur ) return cur; return lastNode[cur] = getLastNode( lastNode[cur] ); } short int LCA(short int U, short int V) { if( prof[U] < prof[V] ) swap( U , V ); short int d = prof[U] - prof[V]; for(short int k = 0 ; k < LOG ; k++) if( d & (1 << k) ) U = dp[k][U]; if( U == V ) return U; for(short 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(short int U, short 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(short int U, short 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; } short int L = LCA( U , V ); mergePath( U , L ); mergePath( V , L ); } int main() { scanf("%d %d",&n,&m); for(short int i = 1 ; i <= n ; i++) { sz[i] = 1; root[i] = i; lastNode[i] = i; } for(short int i = 1 ; i <= m ; i++) { short 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 | 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 | 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 | 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 | Correct | 5 ms | 384 KB | Output is correct |
2 | Runtime error | 5 ms | 512 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 256 KB | Output is correct |
2 | Runtime error | 5 ms | 512 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
# | 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 | Correct | 4 ms | 384 KB | Output is correct |
2 | Incorrect | 5 ms | 384 KB | Wrong number of edges |