# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
91644 | Retro3014 | Islands (IOI08_islands) | C++17 | 462 ms | 39408 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <algorithm>
#include <vector>
typedef long long ll;
using namespace std;
#define MAX_N 1000000
struct E{
int x, y, c;
bool operator <(const E &a)const{
return c<a.c;
}
};
int N, a, b;
vector<E> edge;
ll ans;
int group[MAX_N+1];
int num[MAX_N+1];
int degree[MAX_N+1];
vector<int> vfg;
int find_group(int x){
if(group[x]==group[group[x]]){
return group[x];
}
while(x!=group[x]){
vfg.push_back(x);
x=group[x];
}
while(!vfg.empty()){
group[vfg.back()]=x;
vfg.pop_back();
}
return x;
}
void union_group(int x, int y){
x=find_group(x); y=find_group(y);
if(x==y) return;
if(num[x]>num[y]){int tmp=x; x=y; y=tmp;}
group[x]=y;
num[y]+=num[x];
}
int main(){
scanf("%d", &N);
for(int i=1; i<=N; i++){
group[i]=i; num[i]=1;
scanf("%d%d", &a, &b);
edge.push_back({i, a, b});
}
sort(edge.begin(), edge.end());
while(!edge.empty()){
E now = edge.back();
edge.pop_back();
if(degree[now.x]<=1 && degree[now.y]<=1 && find_group(now.x)!=find_group(now.y)){
union_group(now.x, now.y);
degree[now.x]++; degree[now.y]++;
ans+=(ll)now.c;
}
}
printf("%lld", ans);
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... |
# | 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... |