/*
//\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\\
\\ //
// 271828___182845__904523__53602__ \\
\\ 87___47____13______52____66__24_ //
// 97___75____72______47____09___36 \\
\\ 999595_____74______96____69___67 //
// 62___77____24______07____66__30_ \\
\\ 35___35____47______59____45713__ //
// \\
\\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\//
*/
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <climits>
#include <algorithm>
#include <random>
#include <queue>
#include <deque>
#include <iomanip>
#include <string>
#include <tuple>
#include <bitset>
#include <chrono>
#include <ctime>
#include <fstream>
#include <stack>
#include <cstdio>
#include <functional>
using namespace std;
using LL = long long;
const int N = 1e5 + 5;
const LL mod = 1e9 + 7, inf = 1e18;
vector<int> dx = { 1, 0, 0, -1, 1, 1, -1, -1 };
vector<int> dy = { 0, 1, -1, 0, 1, -1, 1, -1 };
void solve() {
int n, m; cin >> n >> m;
vector<int> s(n);
map<int, vector<int>> srt;
vector<pair<int, int>> vp;
for(int i = 0; i < n; ++i){
cin >> s[i];
srt[s[i]].push_back(i);
vp.push_back({s[i], i});
}
sort(vp.begin(), vp.end());
vector<vector<int>> gp(n);
for(int i = 0; i < m; ++i){
int u, v; cin >> u >> v;
gp[--u].push_back(--v);
gp[v].push_back(u);
}
vector<LL> par(n), sz(n);
for(int i = 0; i < n; ++i){
par[i] = i;
sz[i] = s[i];
}
string ans(n, '1');
function<int(int)> get = [&](int u){
if(par[u] == u) return u;
return get(par[u]);
};
function<void(int u, int v)> unions = [&](int u, int v){
int a = get(u), b = get(v);
if(a == b) return;
par[b] = a;
sz[a] += sz[b];
};
vector<bool> vis(n);
function<int(int)> check = [&](int u){
if(vis[u] != -1) return vis[u];
if(ans[u] == '0') return vis[u] = 0;
if(par[u] == u) return vis[u] = 1;
return vis[u] = check(par[u]);
};
vector<vector<int>> new_gp(n);
function<void(int)> dfs = [&](int u) {
// if(vis[u] != -1) return;
vis[u] = 1;
ans[u] = '0';
for(int &v : new_gp[u]) {
if(!vis[v]){
dfs(v);
}
}
};
for(int i = 0; i < n; ++i){
int cnt = vp[i].first, u = vp[i].second;
for(int &v : gp[u]){
if(s[v] <= s[u]){
int p = get(v);
if(sz[p] < cnt){
// ans[p] = '0';
vis = vector<bool> (n);
dfs(p);
}
}
}
for(int &v : gp[u]){
if(s[v] <= s[u]){
new_gp[v].push_back(u);
new_gp[u].push_back(v);
unions(u, v);
}
}
}
for(int i = 0; i < n; ++i){
// cout << check(i);
cout << ans[i];
}
cout << "\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
// int t; cin >> t; while (t--)
solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
4 ms |
728 KB |
Output is correct |
5 |
Correct |
3 ms |
724 KB |
Output is correct |
6 |
Correct |
6 ms |
468 KB |
Output is correct |
7 |
Correct |
4 ms |
596 KB |
Output is correct |
8 |
Correct |
4 ms |
596 KB |
Output is correct |
9 |
Correct |
7 ms |
596 KB |
Output is correct |
10 |
Correct |
2 ms |
724 KB |
Output is correct |
11 |
Correct |
2 ms |
724 KB |
Output is correct |
12 |
Correct |
2 ms |
724 KB |
Output is correct |
13 |
Correct |
3 ms |
724 KB |
Output is correct |
14 |
Correct |
2 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
255 ms |
50124 KB |
Output is correct |
4 |
Correct |
208 ms |
34236 KB |
Output is correct |
5 |
Correct |
342 ms |
48528 KB |
Output is correct |
6 |
Correct |
300 ms |
45032 KB |
Output is correct |
7 |
Correct |
328 ms |
50132 KB |
Output is correct |
8 |
Correct |
254 ms |
29912 KB |
Output is correct |
9 |
Correct |
267 ms |
44908 KB |
Output is correct |
10 |
Correct |
388 ms |
46528 KB |
Output is correct |
11 |
Correct |
219 ms |
32280 KB |
Output is correct |
12 |
Correct |
319 ms |
30052 KB |
Output is correct |
13 |
Correct |
188 ms |
41356 KB |
Output is correct |
14 |
Correct |
202 ms |
40252 KB |
Output is correct |
15 |
Correct |
211 ms |
50036 KB |
Output is correct |
16 |
Correct |
150 ms |
49448 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
452 ms |
49756 KB |
Output is correct |
3 |
Correct |
423 ms |
44904 KB |
Output is correct |
4 |
Correct |
187 ms |
28852 KB |
Output is correct |
5 |
Correct |
162 ms |
37428 KB |
Output is correct |
6 |
Correct |
448 ms |
49968 KB |
Output is correct |
7 |
Correct |
217 ms |
49988 KB |
Output is correct |
8 |
Correct |
239 ms |
50044 KB |
Output is correct |
9 |
Correct |
149 ms |
49524 KB |
Output is correct |
10 |
Correct |
267 ms |
42672 KB |
Output is correct |
11 |
Correct |
261 ms |
41304 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Execution timed out |
1075 ms |
29372 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
4 ms |
728 KB |
Output is correct |
5 |
Correct |
3 ms |
724 KB |
Output is correct |
6 |
Correct |
6 ms |
468 KB |
Output is correct |
7 |
Correct |
4 ms |
596 KB |
Output is correct |
8 |
Correct |
4 ms |
596 KB |
Output is correct |
9 |
Correct |
7 ms |
596 KB |
Output is correct |
10 |
Correct |
2 ms |
724 KB |
Output is correct |
11 |
Correct |
2 ms |
724 KB |
Output is correct |
12 |
Correct |
2 ms |
724 KB |
Output is correct |
13 |
Correct |
3 ms |
724 KB |
Output is correct |
14 |
Correct |
2 ms |
596 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
255 ms |
50124 KB |
Output is correct |
18 |
Correct |
208 ms |
34236 KB |
Output is correct |
19 |
Correct |
342 ms |
48528 KB |
Output is correct |
20 |
Correct |
300 ms |
45032 KB |
Output is correct |
21 |
Correct |
328 ms |
50132 KB |
Output is correct |
22 |
Correct |
254 ms |
29912 KB |
Output is correct |
23 |
Correct |
267 ms |
44908 KB |
Output is correct |
24 |
Correct |
388 ms |
46528 KB |
Output is correct |
25 |
Correct |
219 ms |
32280 KB |
Output is correct |
26 |
Correct |
319 ms |
30052 KB |
Output is correct |
27 |
Correct |
188 ms |
41356 KB |
Output is correct |
28 |
Correct |
202 ms |
40252 KB |
Output is correct |
29 |
Correct |
211 ms |
50036 KB |
Output is correct |
30 |
Correct |
150 ms |
49448 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
452 ms |
49756 KB |
Output is correct |
33 |
Correct |
423 ms |
44904 KB |
Output is correct |
34 |
Correct |
187 ms |
28852 KB |
Output is correct |
35 |
Correct |
162 ms |
37428 KB |
Output is correct |
36 |
Correct |
448 ms |
49968 KB |
Output is correct |
37 |
Correct |
217 ms |
49988 KB |
Output is correct |
38 |
Correct |
239 ms |
50044 KB |
Output is correct |
39 |
Correct |
149 ms |
49524 KB |
Output is correct |
40 |
Correct |
267 ms |
42672 KB |
Output is correct |
41 |
Correct |
261 ms |
41304 KB |
Output is correct |
42 |
Correct |
0 ms |
212 KB |
Output is correct |
43 |
Execution timed out |
1075 ms |
29372 KB |
Time limit exceeded |
44 |
Halted |
0 ms |
0 KB |
- |