# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
91644 | 2018-12-29T01:55:50 Z | Retro3014 | Islands (IOI08_islands) | C++17 | 462 ms | 39408 KB |
#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; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Incorrect | 2 ms | 376 KB | Output isn't correct |
3 | Correct | 2 ms | 376 KB | Output is correct |
4 | Correct | 2 ms | 376 KB | Output is correct |
5 | Correct | 2 ms | 376 KB | Output is correct |
6 | Correct | 2 ms | 376 KB | Output is correct |
7 | Correct | 2 ms | 376 KB | Output is correct |
8 | Incorrect | 2 ms | 376 KB | Output isn't correct |
9 | Correct | 2 ms | 376 KB | Output is correct |
10 | Correct | 2 ms | 376 KB | Output is correct |
11 | Correct | 2 ms | 376 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 376 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 376 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 7 ms | 1080 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 17 ms | 2288 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 68 ms | 7660 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 150 ms | 15148 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 346 ms | 35560 KB | Output is correct |
2 | Incorrect | 415 ms | 39380 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 462 ms | 39408 KB | Output is correct |
2 | Incorrect | 459 ms | 39408 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |