#include <bits/stdc++.h>
#define vi vector<int>
#define ve vector
#define ll long long
#define vf vector<float>
#define vll vector<pair<ll,ll>>
#define ii pair<int,int>
#define vvi vector<vi>
#define vii vector<ii>
#define gii greater<ii>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF 1e9+7
#define eps 1e-7
#define eps1 1e-2
#define optimise ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MAX_A 2e5+5
using namespace std;
const int MOD = 1e4+7;
const int nax = 2e5+5;
typedef complex<int> Point;
#define X real()
#define Y imag()
vii s;
vi adj[nax], nds[nax];
ll ans[nax];
ll vl[nax], p[nax], sz[nax];
int find_set(int v) {
if (v == p[v])
return v;
return p[v] = find_set(p[v]);
}
void union_sets(int a, int b) {
a = find_set(a);
b = find_set(b);
if (a != b){
//if(nds[b].size() > nds[a].size()) swap(nds[a],nds[b]);
for(auto x : nds[b]) nds[a].pb(x);
p[b] = a;
sz[a] += sz[b];
}
}
int main(){
optimise;
int n,m;
cin >>n >> m;
for (int i = 0; i < n; ++i)
{
int val;
cin >> val;
sz[i] = val;
p[i] = i;
nds[i].pb(i);
s.pb({val,i});
}
for (int i = 0; i < m; ++i)
{
int a,b;
cin >> a >> b;
a--,b--;
if(mp(sz[a],a) < mp(sz[b],b) ) swap(a,b);
adj[a].pb(b);
}
sort(s.begin(), s.end());
for (int i = 0; i < n; ++i)
{
int u = find_set(s[i].se);
for(auto x : adj[u]){
x = find_set(x);
if(sz[u] > sz[x]) nds[x].clear();
}
for(auto x : adj[u]) union_sets(x,u);
}
for(auto x: nds[find_set(0)])
ans[x] = 1;
for (int i = 0; i < n; ++i)
{
cout << ans[i];
}
}
# |
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 |
Correct |
5 ms |
9684 KB |
Output is correct |
4 |
Correct |
7 ms |
10324 KB |
Output is correct |
5 |
Correct |
8 ms |
10028 KB |
Output is correct |
6 |
Correct |
7 ms |
10664 KB |
Output is correct |
7 |
Correct |
6 ms |
10324 KB |
Output is correct |
8 |
Correct |
6 ms |
10196 KB |
Output is correct |
9 |
Correct |
6 ms |
9812 KB |
Output is correct |
10 |
Correct |
6 ms |
9940 KB |
Output is correct |
11 |
Correct |
6 ms |
9940 KB |
Output is correct |
12 |
Correct |
8 ms |
9940 KB |
Output is correct |
13 |
Correct |
6 ms |
9812 KB |
Output is correct |
14 |
Correct |
6 ms |
9940 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
9684 KB |
Output is correct |
2 |
Correct |
6 ms |
9684 KB |
Output is correct |
3 |
Runtime error |
663 ms |
524288 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
9684 KB |
Output is correct |
2 |
Correct |
209 ms |
33460 KB |
Output is correct |
3 |
Correct |
193 ms |
33856 KB |
Output is correct |
4 |
Correct |
153 ms |
31300 KB |
Output is correct |
5 |
Correct |
148 ms |
28656 KB |
Output is correct |
6 |
Correct |
192 ms |
34204 KB |
Output is correct |
7 |
Correct |
152 ms |
30388 KB |
Output is correct |
8 |
Correct |
178 ms |
30512 KB |
Output is correct |
9 |
Correct |
88 ms |
30264 KB |
Output is correct |
10 |
Runtime error |
625 ms |
524288 KB |
Execution killed with signal 9 |
11 |
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 |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
5 ms |
9684 KB |
Output is correct |
3 |
Correct |
5 ms |
9684 KB |
Output is correct |
4 |
Correct |
7 ms |
10324 KB |
Output is correct |
5 |
Correct |
8 ms |
10028 KB |
Output is correct |
6 |
Correct |
7 ms |
10664 KB |
Output is correct |
7 |
Correct |
6 ms |
10324 KB |
Output is correct |
8 |
Correct |
6 ms |
10196 KB |
Output is correct |
9 |
Correct |
6 ms |
9812 KB |
Output is correct |
10 |
Correct |
6 ms |
9940 KB |
Output is correct |
11 |
Correct |
6 ms |
9940 KB |
Output is correct |
12 |
Correct |
8 ms |
9940 KB |
Output is correct |
13 |
Correct |
6 ms |
9812 KB |
Output is correct |
14 |
Correct |
6 ms |
9940 KB |
Output is correct |
15 |
Correct |
6 ms |
9684 KB |
Output is correct |
16 |
Correct |
6 ms |
9684 KB |
Output is correct |
17 |
Runtime error |
663 ms |
524288 KB |
Execution killed with signal 9 |
18 |
Halted |
0 ms |
0 KB |
- |