# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
702211 | lovrot | Stranded Far From Home (BOI22_island) | C++17 | 195 ms | 24700 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <vector>
#include <cstdio>
#include <algorithm>
#define X first
#define Y second
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int N = 2e5 + 10;
int n, m, to[N], U[N], sol[N];
ll S[N], SUM[N];
vector<int> g[N];
vector<pair<ll, int>> p;
int Find(int u) {
if(u == U[u]) return u;
return U[u] = Find(U[u]);
}
void Union(int u, int v) {
v = Find(v);
U[v] = u;
SUM[u] += SUM[v];
if(!to[v] || S[to[v]] == S[v]) to[v] = u;
}
int main() {
for(int i = 0; i < N; i++) U[i] = i;
scanf("%d%d", &n, &m);
for(int i = 1; i <= n; i++) {
scanf("%lld", S + i);
p.pb({S[i], i});
}
sort(p.begin(), p.end());
for(int i = 0; i < m; i++) {
int u, v;
scanf("%d%d", &u, &v);
if(S[u] < S[v] || S[u] == S[v] && u < v) swap(u, v);
g[u].pb(v);
}
for(pair<ll, int> u : p) {
SUM[u.Y] = S[u.Y];
for(int v : g[u.Y]) Union(u.Y, v);
}
reverse(p.begin(), p.end());
to[p[0].Y] = 0;
SUM[0] = 0;
sol[0] = 1;
for(pair<ll, int> u : p)
if(sol[to[u.Y]] && SUM[u.Y] >= S[to[u.Y]]) sol[u.Y] = true;
for(int i = 1; i <= n; i++) printf("%d", sol[i]);
printf("\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... |