# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
220881 | Ruxandra985 | Cities (BOI16_cities) | C++14 | 122 ms | 8056 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define DIMN 100010
using namespace std;
int tt[DIMN] , sp[DIMN];
long long sum[DIMN];
pair <int , pair <int,int> > v[2 * DIMN];
int root (int x){
while (tt[x] > 0)
x = tt[x];
return x;
}
int main()
{
FILE *fin = stdin;
FILE *fout = stdout;
int n , m , k , i , j , x , y , rx , ry , cost;
fscanf (fin,"%d%d%d",&n,&k,&m);
for (i = 1 ; i <= k ; i++)
fscanf (fin,"%d",&sp[i]);
for (i = 1 ; i <= m ; i++)
fscanf (fin,"%d%d%d",&v[i].second.first , &v[i].second.second , &v[i].first);
sort (v + 1 , v + m + 1);
for (i = 1 ; i <= n ; i++)
tt[i] = -1;
for (i = 1 ; i <= m ; i++){
x = v[i].second.first;
y = v[i].second.second;
cost = v[i].first;
rx = root(x);
ry = root(y);
if (rx != ry){
if (tt[rx] < tt[ry]){
tt[rx] += tt[ry];
tt[ry] = rx;
sum[rx] += sum[ry] + cost;
}
else {
tt[ry] += tt[rx];
tt[rx] = ry;
sum[ry] += sum[rx] + cost;
}
}
for (j = 2 ; j <= k ; j++){
if (root(sp[j]) != root(sp[j - 1]))
break;
}
if (j > k)
break;
}
fprintf (fout,"%lld",sum[root(sp[1])]);
return 0;
}
컴파일 시 표준 에러 (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... |