# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
937429 | weakweakweak | Stranded Far From Home (BOI22_island) | C++14 | 175 ms | 43680 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int n, m, s[201000], fa[201000], sz[201000], vis[201000] = {0}, ans[201000], dead[201000] = {0};
ll w[201000];
vector <int> e[201000], ne[201000];
int find (int x) {return fa[x] == x? x : fa[x] = find(fa[x]);}
void dfs(int i) {
ans[i] = !dead[i];
for (int j : ne[i]) {
dead[j] |= dead[i];
dfs(j);
}
return;}
int main () {
//輸入、建圖
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> s[i];
fa[i] = i, w[i] = s[i], sz[i] = 1;
}
for (int i = 0, x, y; i < m; i++) {
cin >> x >> y;
e[x].push_back(y);e[y].push_back(x);
}
//做事
vector<int> p;
for (int i = 1; i <= n; i++) p.push_back(i);
sort(p.begin(), p.end(), [&s](int & a, int & b){return s[a] < s[b];});
for (int ii = 0; ii < n; ii++) {
int i = p[ii];
for (int j : e[i]) {
if (!vis[j] or i == find(j)) continue;
if (w[find(j)] < s[i]) dead[find(j)] = 1;
ne[i].push_back(find(j));
w[i] += w[find(j)];
fa[find(j)] = i;
}
vis[i] = 1;
}
//從根往下跑
int rt = find(1);
dfs(rt);
//輸出
for (int i = 1; i <= n; i++) cout << ans[i];
cout << '\n';
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... |