이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 2e5 + 2;
int n, m, s[MAXN], uf[MAXN], sz[MAXN];
ll sum[MAXN];
vector<int> adj[MAXN], d[MAXN];
vector<pair<int, int> > v;
bool bio[MAXN], ans[MAXN];
int f(int x){
while(uf[x] != -1) x = uf[x];
return x;
}
void join(int u, int v, bool good){
if(u == v) return ;
if(sz[u] > sz[v]) swap(u, v);
uf[u] = v;
sz[v] += sz[u];
sum[v] += sum[u];
if(good){
if(d[v].size() < d[u].size()) swap(d[u], d[v]);
for(int x : d[u]) d[v].push_back(x);
}
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> n >> m;
for(int i = 0; i < n; ++i){
cin >> s[i];
v.push_back({s[i], i});
uf[i] = -1; sz[i] = 1;
d[i] = {i};
sum[i] = s[i];
}
for(int i = 0; i < m; ++i){
int u, v;
cin >> u >> v, --u, --v;
adj[u].push_back(v); adj[v].push_back(u);
}
sort(v.begin(), v.end());
for(pair<int, int> p : v){
for(int x : adj[p.second]){
if(bio[x]){
int root = f(x);
join(root, f(p.second), sum[root] >= s[p.second]);
}
}
bio[p.second] = 1;
}
int source = f(v.back().second);
for(int x : d[source]) ans[x] = 1;
for(int i = 0; i < n; ++i) cout << ans[i];
return 0;
}
# | 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... |