# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
221658 | Lawliet | Pipes (CEOI15_pipes) | C++17 | 5 ms | 512 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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);
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |