/*
//\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\\
\\ //
// 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;
for(int i = 0; i < n; ++i){
cin >> s[i];
srt[s[i]].push_back(i);
}
vector<int> t = s;
sort(t.begin(), t.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');
vector<int> vis(n, -1);
map<pair<int, int>, int> answ;
int tm = 0;
function<int(int, int)> check = [&](int u, int timer){
if(answ.find(make_pair(timer, u)) != answ.end()) {
return answ[make_pair(timer, u)];
}
if(ans[u] == '0') return 0;
if(par[u] == u) return 1;
int r = check(par[u], timer);
if(!r) ans[u] = '0';
answ[make_pair(timer, u)] = r;
return r;
};
function<LL(LL)> get = [&](LL u){
if(par[u] == u) return u;
if(!check(u, tm)) ans[u] = '0';
return par[u] = 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];
};
for(auto x : srt){
vector<int> nodes = x.second;
int cnt = x.first;
for(int &u : nodes){
for(int &v : gp[u]){
if(s[v] <= s[u]){
++tm;
int p = get(v);
if(sz[p] < cnt){
ans[p] = '0';
}
}
}
}
for(int &u : nodes) {
for(int &v : gp[u]){
if(s[v] <= s[u]){
unions(u, v);
}
}
}
}
vis = vector<int> (n, -1);
for(int i = 0; i < n; ++i){
++tm;
get(i);
cout << ans[i];
}
cout << "\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
// int t; cin >> t; while (t--)
solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
4 ms |
1108 KB |
Output is correct |
5 |
Correct |
3 ms |
980 KB |
Output is correct |
6 |
Correct |
4 ms |
724 KB |
Output is correct |
7 |
Correct |
4 ms |
1108 KB |
Output is correct |
8 |
Correct |
5 ms |
1196 KB |
Output is correct |
9 |
Correct |
3 ms |
852 KB |
Output is correct |
10 |
Correct |
3 ms |
852 KB |
Output is correct |
11 |
Correct |
3 ms |
852 KB |
Output is correct |
12 |
Correct |
2 ms |
724 KB |
Output is correct |
13 |
Correct |
3 ms |
724 KB |
Output is correct |
14 |
Correct |
3 ms |
724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
392 ms |
60196 KB |
Output is correct |
4 |
Correct |
494 ms |
42932 KB |
Output is correct |
5 |
Correct |
371 ms |
55216 KB |
Output is correct |
6 |
Correct |
403 ms |
51864 KB |
Output is correct |
7 |
Correct |
399 ms |
57016 KB |
Output is correct |
8 |
Correct |
729 ms |
55580 KB |
Output is correct |
9 |
Correct |
327 ms |
50280 KB |
Output is correct |
10 |
Correct |
175 ms |
35248 KB |
Output is correct |
11 |
Correct |
324 ms |
43812 KB |
Output is correct |
12 |
Correct |
637 ms |
40608 KB |
Output is correct |
13 |
Correct |
469 ms |
42996 KB |
Output is correct |
14 |
Correct |
489 ms |
42900 KB |
Output is correct |
15 |
Correct |
419 ms |
64108 KB |
Output is correct |
16 |
Correct |
370 ms |
63428 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
583 ms |
64304 KB |
Output is correct |
3 |
Correct |
597 ms |
59788 KB |
Output is correct |
4 |
Correct |
448 ms |
42880 KB |
Output is correct |
5 |
Correct |
517 ms |
43004 KB |
Output is correct |
6 |
Correct |
605 ms |
64588 KB |
Output is correct |
7 |
Correct |
594 ms |
76632 KB |
Output is correct |
8 |
Correct |
589 ms |
76604 KB |
Output is correct |
9 |
Correct |
381 ms |
63352 KB |
Output is correct |
10 |
Correct |
439 ms |
64488 KB |
Output is correct |
11 |
Correct |
358 ms |
42336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
523 ms |
50448 KB |
Output is correct |
3 |
Correct |
503 ms |
50244 KB |
Output is correct |
4 |
Correct |
514 ms |
53392 KB |
Output is correct |
5 |
Correct |
930 ms |
55268 KB |
Output is correct |
6 |
Correct |
900 ms |
52548 KB |
Output is correct |
7 |
Correct |
681 ms |
58216 KB |
Output is correct |
8 |
Correct |
510 ms |
66380 KB |
Output is correct |
9 |
Correct |
445 ms |
38676 KB |
Output is correct |
10 |
Correct |
860 ms |
43228 KB |
Output is correct |
11 |
Correct |
344 ms |
45048 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
4 ms |
1108 KB |
Output is correct |
5 |
Correct |
3 ms |
980 KB |
Output is correct |
6 |
Correct |
4 ms |
724 KB |
Output is correct |
7 |
Correct |
4 ms |
1108 KB |
Output is correct |
8 |
Correct |
5 ms |
1196 KB |
Output is correct |
9 |
Correct |
3 ms |
852 KB |
Output is correct |
10 |
Correct |
3 ms |
852 KB |
Output is correct |
11 |
Correct |
3 ms |
852 KB |
Output is correct |
12 |
Correct |
2 ms |
724 KB |
Output is correct |
13 |
Correct |
3 ms |
724 KB |
Output is correct |
14 |
Correct |
3 ms |
724 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
392 ms |
60196 KB |
Output is correct |
18 |
Correct |
494 ms |
42932 KB |
Output is correct |
19 |
Correct |
371 ms |
55216 KB |
Output is correct |
20 |
Correct |
403 ms |
51864 KB |
Output is correct |
21 |
Correct |
399 ms |
57016 KB |
Output is correct |
22 |
Correct |
729 ms |
55580 KB |
Output is correct |
23 |
Correct |
327 ms |
50280 KB |
Output is correct |
24 |
Correct |
175 ms |
35248 KB |
Output is correct |
25 |
Correct |
324 ms |
43812 KB |
Output is correct |
26 |
Correct |
637 ms |
40608 KB |
Output is correct |
27 |
Correct |
469 ms |
42996 KB |
Output is correct |
28 |
Correct |
489 ms |
42900 KB |
Output is correct |
29 |
Correct |
419 ms |
64108 KB |
Output is correct |
30 |
Correct |
370 ms |
63428 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
583 ms |
64304 KB |
Output is correct |
33 |
Correct |
597 ms |
59788 KB |
Output is correct |
34 |
Correct |
448 ms |
42880 KB |
Output is correct |
35 |
Correct |
517 ms |
43004 KB |
Output is correct |
36 |
Correct |
605 ms |
64588 KB |
Output is correct |
37 |
Correct |
594 ms |
76632 KB |
Output is correct |
38 |
Correct |
589 ms |
76604 KB |
Output is correct |
39 |
Correct |
381 ms |
63352 KB |
Output is correct |
40 |
Correct |
439 ms |
64488 KB |
Output is correct |
41 |
Correct |
358 ms |
42336 KB |
Output is correct |
42 |
Correct |
0 ms |
212 KB |
Output is correct |
43 |
Correct |
523 ms |
50448 KB |
Output is correct |
44 |
Correct |
503 ms |
50244 KB |
Output is correct |
45 |
Correct |
514 ms |
53392 KB |
Output is correct |
46 |
Correct |
930 ms |
55268 KB |
Output is correct |
47 |
Correct |
900 ms |
52548 KB |
Output is correct |
48 |
Correct |
681 ms |
58216 KB |
Output is correct |
49 |
Correct |
510 ms |
66380 KB |
Output is correct |
50 |
Correct |
445 ms |
38676 KB |
Output is correct |
51 |
Correct |
860 ms |
43228 KB |
Output is correct |
52 |
Correct |
344 ms |
45048 KB |
Output is correct |
53 |
Correct |
1 ms |
212 KB |
Output is correct |
54 |
Correct |
1 ms |
212 KB |
Output is correct |
55 |
Correct |
1 ms |
212 KB |
Output is correct |
56 |
Correct |
6 ms |
1108 KB |
Output is correct |
57 |
Correct |
4 ms |
976 KB |
Output is correct |
58 |
Correct |
4 ms |
724 KB |
Output is correct |
59 |
Correct |
5 ms |
1108 KB |
Output is correct |
60 |
Correct |
4 ms |
1108 KB |
Output is correct |
61 |
Correct |
3 ms |
852 KB |
Output is correct |
62 |
Correct |
3 ms |
852 KB |
Output is correct |
63 |
Correct |
4 ms |
896 KB |
Output is correct |
64 |
Correct |
3 ms |
852 KB |
Output is correct |
65 |
Correct |
3 ms |
724 KB |
Output is correct |
66 |
Correct |
4 ms |
724 KB |
Output is correct |
67 |
Correct |
413 ms |
64552 KB |
Output is correct |
68 |
Correct |
475 ms |
46116 KB |
Output is correct |
69 |
Correct |
396 ms |
59420 KB |
Output is correct |
70 |
Correct |
397 ms |
56268 KB |
Output is correct |
71 |
Correct |
422 ms |
61416 KB |
Output is correct |
72 |
Correct |
726 ms |
59908 KB |
Output is correct |
73 |
Correct |
336 ms |
54536 KB |
Output is correct |
74 |
Correct |
150 ms |
38836 KB |
Output is correct |
75 |
Correct |
307 ms |
47172 KB |
Output is correct |
76 |
Correct |
590 ms |
43604 KB |
Output is correct |
77 |
Correct |
485 ms |
45968 KB |
Output is correct |
78 |
Correct |
485 ms |
46064 KB |
Output is correct |
79 |
Correct |
440 ms |
68484 KB |
Output is correct |
80 |
Correct |
366 ms |
67120 KB |
Output is correct |
81 |
Correct |
555 ms |
68664 KB |
Output is correct |
82 |
Correct |
542 ms |
64176 KB |
Output is correct |
83 |
Correct |
464 ms |
47504 KB |
Output is correct |
84 |
Correct |
489 ms |
45872 KB |
Output is correct |
85 |
Correct |
592 ms |
68976 KB |
Output is correct |
86 |
Correct |
585 ms |
81080 KB |
Output is correct |
87 |
Correct |
573 ms |
81084 KB |
Output is correct |
88 |
Correct |
372 ms |
68228 KB |
Output is correct |
89 |
Correct |
345 ms |
45396 KB |
Output is correct |
90 |
Correct |
479 ms |
54788 KB |
Output is correct |
91 |
Correct |
491 ms |
54744 KB |
Output is correct |
92 |
Correct |
492 ms |
57916 KB |
Output is correct |
93 |
Correct |
933 ms |
59644 KB |
Output is correct |
94 |
Correct |
935 ms |
56972 KB |
Output is correct |
95 |
Correct |
658 ms |
62796 KB |
Output is correct |
96 |
Correct |
516 ms |
69736 KB |
Output is correct |
97 |
Correct |
411 ms |
41184 KB |
Output is correct |
98 |
Correct |
793 ms |
45904 KB |
Output is correct |
99 |
Correct |
363 ms |
45108 KB |
Output is correct |
100 |
Correct |
342 ms |
48036 KB |
Output is correct |
101 |
Correct |
574 ms |
71952 KB |
Output is correct |
102 |
Correct |
937 ms |
47044 KB |
Output is correct |
103 |
Correct |
738 ms |
95040 KB |
Output is correct |
104 |
Correct |
701 ms |
86924 KB |
Output is correct |