# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
254861 | Lawliet | 다리 (APIO19_bridges) | C++17 | 108 ms | 4472 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 50010;
const int MAXM = 100010;
int n, m, q;
int ord[MAXM];
int U[MAXM], V[MAXM], W[MAXM];
int anc[MAXN], sz[MAXN], pW[MAXN];
int find(int cur, int w = 0)
{
if( anc[cur] == cur || pW[cur] < w ) return cur;
return find( anc[cur] , w );
}
void join(int i, int j, int w)
{
i = find(i); j = find(j);
if( i == j ) return;
if( sz[i] < sz[j] )
swap( i , j );
pW[j] = w;
anc[j] = i;
sz[i] += sz[j];
}
bool cmp(int i, int j) { return W[i] > W[j]; }
void initDSU()
{
for(int i = 1 ; i <= n ; i++)
sz[i] = 1, anc[i] = i;
}
int main()
{
scanf("%d %d",&n,&m);
initDSU();
for(int i = 1 ; i <= m ; i++)
scanf("%d %d %d",&U[i],&V[i],&W[i]);
iota( ord + 1 , ord + m + 1 , 1 );
sort( ord + 1 , ord + m + 1 , cmp );
for(int i = 1 ; i <= m ; i++)
join( U[ ord[i] ] , V[ ord[i] ] , W[ ord[i] ] );
scanf("%d",&q);
for(int i = 1 ; i <= q ; i++)
{
int s, maxW;
scanf("%*d %d %d",&s,&maxW);
printf("%d\n",sz[ find(s , maxW) ]);
}
}
컴파일 시 표준 에러 (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... |