#include <iostream>
#include <algorithm>
#include <functional>
#include <random>
#include <cmath>
#include <vector>
#include <array>
#include <set>
#include <map>
#include <queue>
#include <cassert>
#include <string>
#include <bitset>
#include <numeric>
#include <iomanip>
#include <limits.h>
#include <tuple>
// #pragma GCC optimization ("unroll-loops")
// #pragma GCC optimization ("O3")
// #pragma GCC target ("avx2")
using namespace std;
typedef long long ll;
typedef pair<int, int> pp;
#define per(i,r,l) for(int i = (r); i >= (l); i--)
#define rep(i,l,r) for(int i = (l); i < (r); i++)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define ss second
#define ff first
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll mod = 10321, maxn = 2e5, lg = 22, M = 12299390, inf = ll(1e9) + 5;
ll pw(ll a,ll b,ll md=mod){if(!b)return 1;ll k=pw(a,b>>1ll);return k*k%md*(b&1ll?a:1)%md;}
int par[maxn], s[maxn], vl[maxn];
ll sum[maxn], sumloc[maxn];
vector<int> tp[maxn], adj[maxn];
bool vis[maxn];
int get(int r){
return par[r] == -1? r: par[r] = get(par[r]);
}
int main(){
cin.tie(0) -> sync_with_stdio(0);
int n, m; cin >> n >> m;
rep(i,0,n) cin >> s[i], sum[i] = s[i];
rep(i,0,m){
int u, v; cin >> u >> v; u--, v--;
adj[u].pb(v), adj[v].pb(u);
}
fill(par, par + n, -1);
fill(vl, vl + n, inf);
rep(i,0,n) tp[i].pb(i);
vector<int> id(n); iota(all(id), 0), sort(all(id), [&](int i, int j){ return s[i] < s[j]; });
vector<int> stk;
for(int r: id){ vis[r] = true;
if(sz(stk) && s[r] - s[stk.back()]){
for(int t: stk) sumloc[t] = sum[get(t)];
stk.clear();
}
for(int c: adj[r]) if(vis[c]){ c = get(c);
if(c == r) continue;
par[c] = r, sum[r] += sum[c];
for(int t: tp[c]) if(s[t] == s[r]) tp[r].pb(t);
else vl[t] = r;
tp[c].clear();
}
stk.pb(r);
}
// rep(i,0,n) cout << i << ' ' << get(i) << ' ' << sumloc[i] << ' ' << vl[i] << endl;
vector<bool> ans(n);
for(int t: tp[get(0)]) ans[t] = true;
reverse(all(id));
for(int r: id) if(!ans[r] && sumloc[r] >= s[vl[r]]) ans[r] = ans[vl[r]];
for(bool c: ans) cout << c; cout << '\n';
return 0;
}
Compilation message
island.cpp: In function 'int main()':
island.cpp:84:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
84 | for(bool c: ans) cout << c; cout << '\n';
| ^~~
island.cpp:84:33: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
84 | for(bool c: ans) cout << c; cout << '\n';
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
5 ms |
9624 KB |
Output is correct |
3 |
Correct |
5 ms |
9684 KB |
Output is correct |
4 |
Correct |
6 ms |
9812 KB |
Output is correct |
5 |
Correct |
6 ms |
9940 KB |
Output is correct |
6 |
Correct |
12 ms |
13416 KB |
Output is correct |
7 |
Correct |
6 ms |
9888 KB |
Output is correct |
8 |
Correct |
6 ms |
9860 KB |
Output is correct |
9 |
Correct |
11 ms |
12940 KB |
Output is correct |
10 |
Correct |
6 ms |
9860 KB |
Output is correct |
11 |
Correct |
6 ms |
9844 KB |
Output is correct |
12 |
Correct |
6 ms |
9864 KB |
Output is correct |
13 |
Correct |
8 ms |
11408 KB |
Output is correct |
14 |
Correct |
6 ms |
9988 KB |
Output is correct |
# |
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 |
152 ms |
31032 KB |
Output is correct |
4 |
Runtime error |
954 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 |
Correct |
218 ms |
32072 KB |
Output is correct |
3 |
Correct |
244 ms |
31412 KB |
Output is correct |
4 |
Correct |
983 ms |
524288 KB |
Output is correct |
5 |
Correct |
983 ms |
508904 KB |
Output is correct |
6 |
Correct |
229 ms |
30932 KB |
Output is correct |
7 |
Correct |
179 ms |
31156 KB |
Output is correct |
8 |
Correct |
169 ms |
31052 KB |
Output is correct |
9 |
Correct |
124 ms |
30280 KB |
Output is correct |
10 |
Correct |
656 ms |
352012 KB |
Output is correct |
11 |
Correct |
221 ms |
46536 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
9752 KB |
Output is correct |
2 |
Execution timed out |
1061 ms |
521540 KB |
Time limit exceeded |
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 |
9624 KB |
Output is correct |
3 |
Correct |
5 ms |
9684 KB |
Output is correct |
4 |
Correct |
6 ms |
9812 KB |
Output is correct |
5 |
Correct |
6 ms |
9940 KB |
Output is correct |
6 |
Correct |
12 ms |
13416 KB |
Output is correct |
7 |
Correct |
6 ms |
9888 KB |
Output is correct |
8 |
Correct |
6 ms |
9860 KB |
Output is correct |
9 |
Correct |
11 ms |
12940 KB |
Output is correct |
10 |
Correct |
6 ms |
9860 KB |
Output is correct |
11 |
Correct |
6 ms |
9844 KB |
Output is correct |
12 |
Correct |
6 ms |
9864 KB |
Output is correct |
13 |
Correct |
8 ms |
11408 KB |
Output is correct |
14 |
Correct |
6 ms |
9988 KB |
Output is correct |
15 |
Correct |
6 ms |
9684 KB |
Output is correct |
16 |
Correct |
7 ms |
9684 KB |
Output is correct |
17 |
Correct |
152 ms |
31032 KB |
Output is correct |
18 |
Runtime error |
954 ms |
524288 KB |
Execution killed with signal 9 |
19 |
Halted |
0 ms |
0 KB |
- |