이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define name "cownav"
#define fi(i,a,b) for(int i = a; i <= b; i++)
#define fid(i,a,b) for(int i = a; i >= b; i--)
#define int long long
#define ll long long
#define f first
#define se second
#define pii pair<int, ll>
#define getbit(i, j) ((i >> j) & 1)
#define pb push_back
#define all(v) v.begin(), v.end()
#define maxn 200005
const int M = 1e9 + 7;
using namespace std;
mt19937_64 rng(time(0));
int n, m, root[maxn], sz[maxn], ans[maxn], xd[maxn];
pii a[maxn];
vector <int> g[maxn], f[maxn];
int get(int u){
if(root[u] == 0) return u;
return (root[u] = get(root[u]));
}
void dfs(int u, int ok){
ans[u] &= ok;
for(auto v: f[u]) dfs(v, ans[u]);
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(NULL);
//freopen(name".inp","r",stdin);
// freopen(name".out","w",stdout);
cin >> n >> m;
fi(i, 1, n){
int x; cin >> x;
a[i] = {x, i};
sz[i] = x;
}
fi(i, 1, m){
int u, v; cin >> u >> v;
g[u].pb(v); g[v].pb(u);
}
sort(a + 1, a + n + 1);
fi(i, 1, n) ans[i] = 1;
fi(i, 1, n){
auto [w, u] = a[i];
for(auto v: g[u]) if(xd[v]){
int x = get(v);
if(x == u) continue;
f[u].pb(x);
root[x] = u;
sz[u] += sz[x];
if(sz[x] < w) ans[x] = 0;
}
xd[u] = 1;
}
dfs(a[n].se, 1);
fi(i, 1, n) 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... |