#include <bits/stdc++.h>
#define int long long
#define pi pair <int, int>
#define ppi pair <pi, int>
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define debug(x) cout << #x << ": " << x << '\n'
#define debug2(x, y) cout << #x << ": " << x << ' ' << #y << ": " << y << '\n'
#define debug3(x, y, z) cout << #x << ": " << x << ' ' << #y << ": " << y << ' ' << #z << ": " << z << '\n'
#define debug4(x, y, z, w) cout << #x << ": " << x << ' ' << #y << ": " << y << ' ' << #z << ": " << z << ' ' << #w << ": " << w << '\n'
using namespace std;
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());
const int inf = 1000000000000000000, mod = 998244353;
int n, m, root[200005], val[200005], sz[200005];
pi s[200005];
vector <int> nodes[200005];
vector <int> adj[200005];
bool processed[200005], ans[200005];
int getroot(int x){
if(x == root[x]) return x;
else return root[x] = getroot(root[x]);
}
void merge(int x, int y){
int rootx = getroot(x), rooty = getroot(y);
//debug4(x, rootx, y, rooty);
if(rootx == rooty) return;
if(sz[rootx] < sz[rooty]) swap(rootx, rooty), swap(nodes[rootx], nodes[rooty]);
root[rooty] = rootx, sz[rootx] += sz[rooty], val[rootx] += val[rooty];
for(auto it = nodes[rooty].begin(); it != nodes[rooty].end(); it++) nodes[rootx].pb(*it);
nodes[rooty].clear();
//cout << "merged: " << x << ", " << y << '\n';
}
void mark(int x){
for(auto it = nodes[x].begin(); it != nodes[x].end(); it++) ans[*it] = 0;
}
signed main(){
ios::sync_with_stdio(0), cin.tie(0);
cin >> n >> m;
fill(ans+1, ans+n+1, 0);
for(int i = 1; i <= n; i++){
cin >> s[i].fi;
s[i].se = i, root[i] = i, val[i] = s[i].fi, sz[i] = 1;
nodes[i].pb(i);
}
for(int i = 1; i <= m; i++){
int a, b; cin >> a >> b;
adj[a].pb(b), adj[b].pb(a);
}
sort(s+1, s+n+1);
for(int i = 1; i <= n; i++){
processed[s[i].se] = 1;
for(int j : adj[s[i].se]){
//debug3(s[i].se, j, processed[j]);
if(!processed[j]) continue;
int k = getroot(j);
//debug4(s[i].se, s[i].fi, k, val[k]);
if(s[i].fi > val[k]){
nodes[k].clear();
}
merge(s[i].se, k);
}
}
for(int i = 1; i <= n; i++){
if(i != getroot(i)) continue;
for(auto it = nodes[i].begin(); it != nodes[i].end(); it++) ans[*it] = 1;
}
for(int i = 1; i <= n; i++) cout << ans[i];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
9684 KB |
Output is correct |
2 |
Correct |
7 ms |
9684 KB |
Output is correct |
3 |
Correct |
7 ms |
9684 KB |
Output is correct |
4 |
Correct |
11 ms |
13428 KB |
Output is correct |
5 |
Correct |
7 ms |
10836 KB |
Output is correct |
6 |
Correct |
12 ms |
15716 KB |
Output is correct |
7 |
Correct |
9 ms |
13396 KB |
Output is correct |
8 |
Correct |
8 ms |
13088 KB |
Output is correct |
9 |
Correct |
17 ms |
20436 KB |
Output is correct |
10 |
Correct |
6 ms |
10068 KB |
Output is correct |
11 |
Correct |
7 ms |
9996 KB |
Output is correct |
12 |
Correct |
6 ms |
9940 KB |
Output is correct |
13 |
Correct |
21 ms |
29432 KB |
Output is correct |
14 |
Correct |
7 ms |
10324 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
5 ms |
9684 KB |
Output is correct |
3 |
Runtime error |
528 ms |
524288 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
243 ms |
53776 KB |
Output is correct |
3 |
Correct |
279 ms |
55096 KB |
Output is correct |
4 |
Runtime error |
489 ms |
524288 KB |
Execution killed with signal 9 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Runtime error |
731 ms |
524288 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
9684 KB |
Output is correct |
2 |
Correct |
7 ms |
9684 KB |
Output is correct |
3 |
Correct |
7 ms |
9684 KB |
Output is correct |
4 |
Correct |
11 ms |
13428 KB |
Output is correct |
5 |
Correct |
7 ms |
10836 KB |
Output is correct |
6 |
Correct |
12 ms |
15716 KB |
Output is correct |
7 |
Correct |
9 ms |
13396 KB |
Output is correct |
8 |
Correct |
8 ms |
13088 KB |
Output is correct |
9 |
Correct |
17 ms |
20436 KB |
Output is correct |
10 |
Correct |
6 ms |
10068 KB |
Output is correct |
11 |
Correct |
7 ms |
9996 KB |
Output is correct |
12 |
Correct |
6 ms |
9940 KB |
Output is correct |
13 |
Correct |
21 ms |
29432 KB |
Output is correct |
14 |
Correct |
7 ms |
10324 KB |
Output is correct |
15 |
Correct |
5 ms |
9684 KB |
Output is correct |
16 |
Correct |
5 ms |
9684 KB |
Output is correct |
17 |
Runtime error |
528 ms |
524288 KB |
Execution killed with signal 9 |
18 |
Halted |
0 ms |
0 KB |
- |