#include <iostream>
#include <vector>
#include <tuple>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <map>
#include <cmath>
#include <random>
#include <string>
#include <bitset>
#include <cassert>
#include <climits>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
using namespace std;
#define ll long long
#define f first
#define s second
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template<typename A> void __print(const A &x);
template<typename A, typename B> void __print(const pair<A, B> &p);
template<typename... A> void __print(const tuple<A...> &t);
template<typename T> void __print(stack<T> s);
template<typename T> void __print(queue<T> q);
template<typename T, typename... U> void __print(priority_queue<T, U...> q);
template<typename A> void __print(const A &x) {
bool first = true;
cerr << '{';
for (const auto &i : x) {
cerr << (first ? "" : ","), __print(i);
first = false;
}
cerr << '}';
}
template<typename A, typename B> void __print(const pair<A, B> &p) {
cerr << '(';
__print(p.f);
cerr << ',';
__print(p.s);
cerr << ')';
}
template<typename... A> void __print(const tuple<A...> &t) {
bool first = true;
cerr << '(';
apply([&first] (const auto &...args) { ((cerr << (first ? "" : ","), __print(args), first = false), ...); }, t);
cerr << ')';
}
template<typename T> void __print(stack<T> s) {
vector<T> debugVector;
while (!s.empty()) {
T t = s.top();
debugVector.push_back(t);
s.pop();
}
reverse(debugVector.begin(), debugVector.end());
__print(debugVector);
}
template<typename T> void __print(queue<T> q) {
vector<T> debugVector;
while (!q.empty()) {
T t = q.front();
debugVector.push_back(t);
q.pop();
}
__print(debugVector);
}
template<typename T, typename... U> void __print(priority_queue<T, U...> q) {
vector<T> debugVector;
while (!q.empty()) {
T t = q.top();
debugVector.push_back(t);
q.pop();
}
__print(debugVector);
}
void _print() { cerr << "]\n"; }
template <typename Head, typename... Tail> void _print(const Head &H, const Tail &...T) {
__print(H);
if (sizeof...(T)) cerr << ", ";
_print(T...);
}
#ifdef DEBUG
#define D(...) cerr << "Line: " << __LINE__ << " [" << #__VA_ARGS__ << "] = ["; _print(__VA_ARGS__)
#else
#define D(...)
#endif
int n, m, s[200005];
ll sm[200005];
vector<pair<ll, int>> ord;
vector<int> adj[200005];
bool ans[200005];
struct UnionFind {
int par[200005];
ll nx[200005];
UnionFind() {
for (int i = 0; i < 200005; i++) {
par[i] = i;
nx[i] = 0;
}
}
int find(int x) {
return par[x] == x ? x : par[x] = find(par[x]);
}
void merge(int x, int y) {
x = find(x);
y = find(y);
if (x != y) {
par[y] = x;
sm[x] += sm[y];
if (!nx[y] || s[nx[y]] == s[y]) nx[y] = x;
}
}
} uf;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> s[i];
ord.push_back({s[i], i});
}
sort(ord.begin(), ord.end());
for (int i = 0, a, b; i < m; i++) {
cin >> a >> b;
if (make_pair(s[a], a) < make_pair(s[b], b)) swap(a, b);
adj[a].push_back(b);
}
for (auto [v, i] : ord) {
sm[i] = s[i];
for (int j : adj[i]) {
uf.merge(i, j);
}
}
reverse(ord.begin(), ord.end());
uf.nx[ord[0].second] = 0;
ans[0] = 1;
for (auto [v, i] : ord) {
if (ans[uf.nx[i]] && sm[i] >= s[uf.nx[i]]) {
ans[i] = true;
}
}
for (int i = 1; i <= n; i++) {
cout << ans[i];
}
cout << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
7508 KB |
Output is correct |
2 |
Correct |
4 ms |
7380 KB |
Output is correct |
3 |
Correct |
3 ms |
7360 KB |
Output is correct |
4 |
Correct |
4 ms |
7388 KB |
Output is correct |
5 |
Correct |
4 ms |
7468 KB |
Output is correct |
6 |
Correct |
4 ms |
7380 KB |
Output is correct |
7 |
Correct |
4 ms |
7508 KB |
Output is correct |
8 |
Correct |
4 ms |
7444 KB |
Output is correct |
9 |
Correct |
4 ms |
7508 KB |
Output is correct |
10 |
Correct |
4 ms |
7508 KB |
Output is correct |
11 |
Correct |
4 ms |
7508 KB |
Output is correct |
12 |
Correct |
4 ms |
7508 KB |
Output is correct |
13 |
Correct |
4 ms |
7508 KB |
Output is correct |
14 |
Correct |
4 ms |
7380 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
7380 KB |
Output is correct |
2 |
Correct |
3 ms |
7380 KB |
Output is correct |
3 |
Correct |
77 ms |
21888 KB |
Output is correct |
4 |
Correct |
80 ms |
23740 KB |
Output is correct |
5 |
Correct |
78 ms |
21008 KB |
Output is correct |
6 |
Correct |
94 ms |
21524 KB |
Output is correct |
7 |
Correct |
78 ms |
21540 KB |
Output is correct |
8 |
Correct |
93 ms |
23804 KB |
Output is correct |
9 |
Correct |
73 ms |
20544 KB |
Output is correct |
10 |
Correct |
57 ms |
18336 KB |
Output is correct |
11 |
Correct |
87 ms |
22856 KB |
Output is correct |
12 |
Correct |
77 ms |
21656 KB |
Output is correct |
13 |
Correct |
70 ms |
25244 KB |
Output is correct |
14 |
Correct |
76 ms |
25144 KB |
Output is correct |
15 |
Correct |
74 ms |
23832 KB |
Output is correct |
16 |
Correct |
60 ms |
23104 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
7380 KB |
Output is correct |
2 |
Correct |
96 ms |
21700 KB |
Output is correct |
3 |
Correct |
98 ms |
21800 KB |
Output is correct |
4 |
Correct |
110 ms |
23956 KB |
Output is correct |
5 |
Correct |
69 ms |
23196 KB |
Output is correct |
6 |
Correct |
96 ms |
21728 KB |
Output is correct |
7 |
Correct |
90 ms |
23948 KB |
Output is correct |
8 |
Correct |
98 ms |
23948 KB |
Output is correct |
9 |
Correct |
66 ms |
23268 KB |
Output is correct |
10 |
Correct |
74 ms |
21644 KB |
Output is correct |
11 |
Correct |
88 ms |
20760 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
7380 KB |
Output is correct |
2 |
Correct |
104 ms |
21580 KB |
Output is correct |
3 |
Correct |
97 ms |
21500 KB |
Output is correct |
4 |
Correct |
115 ms |
21560 KB |
Output is correct |
5 |
Correct |
98 ms |
21572 KB |
Output is correct |
6 |
Correct |
106 ms |
21048 KB |
Output is correct |
7 |
Correct |
69 ms |
21404 KB |
Output is correct |
8 |
Correct |
62 ms |
24256 KB |
Output is correct |
9 |
Correct |
61 ms |
15632 KB |
Output is correct |
10 |
Correct |
78 ms |
19836 KB |
Output is correct |
11 |
Correct |
83 ms |
20812 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
7508 KB |
Output is correct |
2 |
Correct |
4 ms |
7380 KB |
Output is correct |
3 |
Correct |
3 ms |
7360 KB |
Output is correct |
4 |
Correct |
4 ms |
7388 KB |
Output is correct |
5 |
Correct |
4 ms |
7468 KB |
Output is correct |
6 |
Correct |
4 ms |
7380 KB |
Output is correct |
7 |
Correct |
4 ms |
7508 KB |
Output is correct |
8 |
Correct |
4 ms |
7444 KB |
Output is correct |
9 |
Correct |
4 ms |
7508 KB |
Output is correct |
10 |
Correct |
4 ms |
7508 KB |
Output is correct |
11 |
Correct |
4 ms |
7508 KB |
Output is correct |
12 |
Correct |
4 ms |
7508 KB |
Output is correct |
13 |
Correct |
4 ms |
7508 KB |
Output is correct |
14 |
Correct |
4 ms |
7380 KB |
Output is correct |
15 |
Correct |
3 ms |
7380 KB |
Output is correct |
16 |
Correct |
3 ms |
7380 KB |
Output is correct |
17 |
Correct |
77 ms |
21888 KB |
Output is correct |
18 |
Correct |
80 ms |
23740 KB |
Output is correct |
19 |
Correct |
78 ms |
21008 KB |
Output is correct |
20 |
Correct |
94 ms |
21524 KB |
Output is correct |
21 |
Correct |
78 ms |
21540 KB |
Output is correct |
22 |
Correct |
93 ms |
23804 KB |
Output is correct |
23 |
Correct |
73 ms |
20544 KB |
Output is correct |
24 |
Correct |
57 ms |
18336 KB |
Output is correct |
25 |
Correct |
87 ms |
22856 KB |
Output is correct |
26 |
Correct |
77 ms |
21656 KB |
Output is correct |
27 |
Correct |
70 ms |
25244 KB |
Output is correct |
28 |
Correct |
76 ms |
25144 KB |
Output is correct |
29 |
Correct |
74 ms |
23832 KB |
Output is correct |
30 |
Correct |
60 ms |
23104 KB |
Output is correct |
31 |
Correct |
3 ms |
7380 KB |
Output is correct |
32 |
Correct |
96 ms |
21700 KB |
Output is correct |
33 |
Correct |
98 ms |
21800 KB |
Output is correct |
34 |
Correct |
110 ms |
23956 KB |
Output is correct |
35 |
Correct |
69 ms |
23196 KB |
Output is correct |
36 |
Correct |
96 ms |
21728 KB |
Output is correct |
37 |
Correct |
90 ms |
23948 KB |
Output is correct |
38 |
Correct |
98 ms |
23948 KB |
Output is correct |
39 |
Correct |
66 ms |
23268 KB |
Output is correct |
40 |
Correct |
74 ms |
21644 KB |
Output is correct |
41 |
Correct |
88 ms |
20760 KB |
Output is correct |
42 |
Correct |
3 ms |
7380 KB |
Output is correct |
43 |
Correct |
104 ms |
21580 KB |
Output is correct |
44 |
Correct |
97 ms |
21500 KB |
Output is correct |
45 |
Correct |
115 ms |
21560 KB |
Output is correct |
46 |
Correct |
98 ms |
21572 KB |
Output is correct |
47 |
Correct |
106 ms |
21048 KB |
Output is correct |
48 |
Correct |
69 ms |
21404 KB |
Output is correct |
49 |
Correct |
62 ms |
24256 KB |
Output is correct |
50 |
Correct |
61 ms |
15632 KB |
Output is correct |
51 |
Correct |
78 ms |
19836 KB |
Output is correct |
52 |
Correct |
83 ms |
20812 KB |
Output is correct |
53 |
Correct |
3 ms |
7376 KB |
Output is correct |
54 |
Correct |
3 ms |
7376 KB |
Output is correct |
55 |
Correct |
3 ms |
7380 KB |
Output is correct |
56 |
Correct |
3 ms |
7508 KB |
Output is correct |
57 |
Correct |
4 ms |
7392 KB |
Output is correct |
58 |
Correct |
4 ms |
7380 KB |
Output is correct |
59 |
Correct |
5 ms |
7488 KB |
Output is correct |
60 |
Correct |
4 ms |
7508 KB |
Output is correct |
61 |
Correct |
4 ms |
7508 KB |
Output is correct |
62 |
Correct |
4 ms |
7508 KB |
Output is correct |
63 |
Correct |
4 ms |
7508 KB |
Output is correct |
64 |
Correct |
4 ms |
7380 KB |
Output is correct |
65 |
Correct |
3 ms |
7480 KB |
Output is correct |
66 |
Correct |
4 ms |
7380 KB |
Output is correct |
67 |
Correct |
79 ms |
21936 KB |
Output is correct |
68 |
Correct |
78 ms |
23688 KB |
Output is correct |
69 |
Correct |
76 ms |
21032 KB |
Output is correct |
70 |
Correct |
81 ms |
21444 KB |
Output is correct |
71 |
Correct |
76 ms |
21524 KB |
Output is correct |
72 |
Correct |
89 ms |
23904 KB |
Output is correct |
73 |
Correct |
69 ms |
20508 KB |
Output is correct |
74 |
Correct |
58 ms |
18412 KB |
Output is correct |
75 |
Correct |
87 ms |
22804 KB |
Output is correct |
76 |
Correct |
80 ms |
21688 KB |
Output is correct |
77 |
Correct |
83 ms |
25348 KB |
Output is correct |
78 |
Correct |
72 ms |
25144 KB |
Output is correct |
79 |
Correct |
101 ms |
23852 KB |
Output is correct |
80 |
Correct |
60 ms |
23004 KB |
Output is correct |
81 |
Correct |
97 ms |
21824 KB |
Output is correct |
82 |
Correct |
99 ms |
21816 KB |
Output is correct |
83 |
Correct |
91 ms |
23960 KB |
Output is correct |
84 |
Correct |
69 ms |
23104 KB |
Output is correct |
85 |
Correct |
99 ms |
21824 KB |
Output is correct |
86 |
Correct |
96 ms |
23928 KB |
Output is correct |
87 |
Correct |
90 ms |
23956 KB |
Output is correct |
88 |
Correct |
75 ms |
21688 KB |
Output is correct |
89 |
Correct |
82 ms |
20764 KB |
Output is correct |
90 |
Correct |
98 ms |
21540 KB |
Output is correct |
91 |
Correct |
102 ms |
21552 KB |
Output is correct |
92 |
Correct |
108 ms |
21660 KB |
Output is correct |
93 |
Correct |
99 ms |
21656 KB |
Output is correct |
94 |
Correct |
87 ms |
21068 KB |
Output is correct |
95 |
Correct |
79 ms |
21524 KB |
Output is correct |
96 |
Correct |
64 ms |
24260 KB |
Output is correct |
97 |
Correct |
64 ms |
15704 KB |
Output is correct |
98 |
Correct |
73 ms |
19896 KB |
Output is correct |
99 |
Correct |
85 ms |
20840 KB |
Output is correct |
100 |
Correct |
31 ms |
10700 KB |
Output is correct |
101 |
Correct |
101 ms |
21660 KB |
Output is correct |
102 |
Correct |
92 ms |
19264 KB |
Output is correct |
103 |
Correct |
93 ms |
19812 KB |
Output is correct |
104 |
Correct |
100 ms |
21416 KB |
Output is correct |