# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
417905 | 2021-06-04T13:34:35 Z | 반딧불(#7603) | Rooted MST (innopolis2021_final_E) | C++17 | 4000 ms | 35680 KB |
#include <bits/stdc++.h> using namespace std; typedef long long ll; struct Edge{ int x, y; ll z; Edge(){} Edge(int x, int y, ll z): x(x), y(y), z(z){} bool operator<(const Edge &r)const{ return z > r.z; } }; struct DisjointSet{ int n; int par[300002]; int sz[300002]; void init(int _n){ n = _n; for(int i=0; i<=n; i++) par[i] = i, sz[i] = 1; } int find(int x){ if(x == par[x]) return x; return par[x] = find(par[x]); } void merge(int x, int y){ x = find(x), y = find(y); if(x==y) return; if(sz[x] < sz[y]) swap(x, y); par[y] = x; sz[x] += sz[y]; } }; int n, m, q; ll arr[300002]; Edge link[300002]; ll dflt; ll lim; ll printMST(){ priority_queue<Edge> pq; for(int i=1; i<=m; i++) pq.push(link[i]); for(int i=1; i<=n; i++){ pq.push(Edge(0, i, arr[i])); } DisjointSet dsu; dsu.init(n); ll ans = 0; while(!pq.empty()){ Edge tmp = pq.top(); pq.pop(); int x = tmp.x, y = tmp.y; if(dsu.find(x) == dsu.find(y)) continue; dsu.merge(x, y); ans += tmp.z; } return ans; } int main(){ scanf("%d %d", &n, &m); for(int i=1; i<=n; i++){ scanf("%lld", &arr[i]); } for(int i=1; i<=m; i++){ scanf("%d %d %lld", &link[i].x, &link[i].y, &link[i].z); } arr[1] = 0; dflt = printMST(); ll MIN = 0, MAX = 1e9 + 1, ANS = 0; while(MIN <= MAX){ ll MID = (MIN + MAX) / 2; arr[1] = MID; if(printMST() == dflt + MID){ ANS = MID; MIN = MID + 1; } else MAX = MID - 1; } lim = ANS; scanf("%d", &q); while(q--){ ll x; scanf("%lld %lld", &x, &x); printf("%lld\n", dflt + min(lim, x)); } }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 2636 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 3659 ms | 35612 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 2659 ms | 20436 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3565 ms | 18084 KB | Output is correct |
2 | Correct | 3689 ms | 18300 KB | Output is correct |
3 | Correct | 3689 ms | 18348 KB | Output is correct |
4 | Correct | 2554 ms | 20456 KB | Output is correct |
5 | Correct | 1449 ms | 13136 KB | Output is correct |
6 | Correct | 382 ms | 7136 KB | Output is correct |
7 | Execution timed out | 4075 ms | 35680 KB | Time limit exceeded |
8 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3565 ms | 18084 KB | Output is correct |
2 | Correct | 3689 ms | 18300 KB | Output is correct |
3 | Correct | 3689 ms | 18348 KB | Output is correct |
4 | Correct | 2554 ms | 20456 KB | Output is correct |
5 | Correct | 1449 ms | 13136 KB | Output is correct |
6 | Correct | 382 ms | 7136 KB | Output is correct |
7 | Execution timed out | 4075 ms | 35680 KB | Time limit exceeded |
8 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Execution timed out | 4061 ms | 35560 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 2636 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 2636 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |