#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define FOR(i, a, b) for (int i = a; i <= b; i++)
#define FORD(i, a, b) for (int i = b; i >= a; i --)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPD(i, n) for (int i = n - 1; i >= 0; --i)
#define MASK(i) (1LL << (i))
#define BIT(x, i) (((x) >> (i)) & 1)
constexpr ll LINF = (1ll << 60);
constexpr int INF = (1ll << 30);
constexpr int Mod = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void setupIO(){
#define name "Whisper"
//Phu Trong from Nguyen Tat Thanh High School for gifted student
srand(time(NULL));
cin.tie(nullptr)->sync_with_stdio(false); cout.tie(nullptr);
//freopen(name".inp", "r", stdin);
//freopen(name".out", "w", stdout);
cout << fixed << setprecision(10);
}
template <class X, class Y>
bool minimize(X &x, const Y &y){
X eps = 1e-9;
if (x > y + eps) {x = y; return 1;}
return 0;
}
template <class X, class Y>
bool maximize(X &x, const Y &y){
X eps = 1e-9;
if (x + eps < y) {x = y; return 1;}
return 0;
}
const int MAX = 2e5 + 5;
int numNode, numEdge;
struct Edge{
int u, v, w;
Edge(){}
Edge(int _u, int _v, int _w): u(_u), v(_v), w(_w){}
int other(int x){ return (u ^ v ^ x); }
bool operator < (const Edge& oth) const{
return w < oth.w;
}
} edge[MAX];
int label[MAX];
int par[MAX], sz[MAX], sum[MAX];
bool bad[MAX];
int find(int u){
if(u == par[u]) return u;
int v = find(par[u]);
bad[u] |= bad[par[u]];
return par[u] = v;
}
bool unite(int u, int v){
u = find(u), v = find(v);
if(u == v) return false;
if(label[u] < label[v]) swap(u, v);
if (label[u] > sum[v]) bad[v] = 1;
sum[u] += sum[v];
par[v] = u;
return true;
}
void Whisper(){
cin >> numNode >> numEdge;
for (int i = 1; i <= numNode; ++i) cin >> label[i];
FOR(i, 1, numNode){
par[i] = i, sz[i] = 1, sum[i] = label[i];
}
vector<Edge> ed;
for (int i = 1; i <= numEdge; ++i){
cin >> edge[i].u >> edge[i].v;
int w = max(label[edge[i].u], label[edge[i].v]);
ed.push_back(Edge(edge[i].u, edge[i].v, w));
}
sort(ed.begin(), ed.end());
for (int i = 0; i < numEdge; ++i){
int u = ed[i].u, v = ed[i].v;
unite(u, v);
}
for (int i = 1; i <= numNode; ++i){
find(i);
cout << !bad[i];
}
}
signed main(){
setupIO();
int Test = 1;
// cin >> Test;
for ( int i = 1 ; i <= Test ; i++ ){
Whisper();
if (i < Test) cout << '\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
8536 KB |
Output is correct |
2 |
Correct |
2 ms |
8536 KB |
Output is correct |
3 |
Correct |
2 ms |
6492 KB |
Output is correct |
4 |
Correct |
2 ms |
8796 KB |
Output is correct |
5 |
Correct |
2 ms |
8612 KB |
Output is correct |
6 |
Correct |
2 ms |
8792 KB |
Output is correct |
7 |
Correct |
2 ms |
8796 KB |
Output is correct |
8 |
Correct |
3 ms |
8796 KB |
Output is correct |
9 |
Correct |
2 ms |
8796 KB |
Output is correct |
10 |
Correct |
3 ms |
8708 KB |
Output is correct |
11 |
Correct |
2 ms |
8676 KB |
Output is correct |
12 |
Correct |
2 ms |
8704 KB |
Output is correct |
13 |
Correct |
2 ms |
8672 KB |
Output is correct |
14 |
Correct |
2 ms |
8672 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
8540 KB |
Output is correct |
2 |
Correct |
1 ms |
6612 KB |
Output is correct |
3 |
Correct |
76 ms |
20268 KB |
Output is correct |
4 |
Correct |
69 ms |
18784 KB |
Output is correct |
5 |
Correct |
70 ms |
20040 KB |
Output is correct |
6 |
Correct |
72 ms |
20676 KB |
Output is correct |
7 |
Correct |
75 ms |
20676 KB |
Output is correct |
8 |
Correct |
80 ms |
19856 KB |
Output is correct |
9 |
Correct |
82 ms |
20160 KB |
Output is correct |
10 |
Correct |
55 ms |
20028 KB |
Output is correct |
11 |
Correct |
63 ms |
20672 KB |
Output is correct |
12 |
Correct |
59 ms |
20416 KB |
Output is correct |
13 |
Correct |
55 ms |
19640 KB |
Output is correct |
14 |
Correct |
62 ms |
19764 KB |
Output is correct |
15 |
Correct |
70 ms |
20796 KB |
Output is correct |
16 |
Correct |
54 ms |
19612 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
74 ms |
20288 KB |
Output is correct |
3 |
Correct |
80 ms |
20400 KB |
Output is correct |
4 |
Correct |
64 ms |
20160 KB |
Output is correct |
5 |
Correct |
55 ms |
19168 KB |
Output is correct |
6 |
Correct |
93 ms |
19548 KB |
Output is correct |
7 |
Correct |
75 ms |
20692 KB |
Output is correct |
8 |
Correct |
77 ms |
19712 KB |
Output is correct |
9 |
Correct |
60 ms |
20400 KB |
Output is correct |
10 |
Correct |
61 ms |
19652 KB |
Output is correct |
11 |
Correct |
59 ms |
19056 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
87 ms |
21260 KB |
Output is correct |
3 |
Correct |
71 ms |
21420 KB |
Output is correct |
4 |
Correct |
75 ms |
21076 KB |
Output is correct |
5 |
Correct |
69 ms |
21048 KB |
Output is correct |
6 |
Correct |
68 ms |
20932 KB |
Output is correct |
7 |
Correct |
66 ms |
21308 KB |
Output is correct |
8 |
Correct |
55 ms |
19848 KB |
Output is correct |
9 |
Correct |
64 ms |
18628 KB |
Output is correct |
10 |
Correct |
70 ms |
18992 KB |
Output is correct |
11 |
Correct |
64 ms |
19516 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
8536 KB |
Output is correct |
2 |
Correct |
2 ms |
8536 KB |
Output is correct |
3 |
Correct |
2 ms |
6492 KB |
Output is correct |
4 |
Correct |
2 ms |
8796 KB |
Output is correct |
5 |
Correct |
2 ms |
8612 KB |
Output is correct |
6 |
Correct |
2 ms |
8792 KB |
Output is correct |
7 |
Correct |
2 ms |
8796 KB |
Output is correct |
8 |
Correct |
3 ms |
8796 KB |
Output is correct |
9 |
Correct |
2 ms |
8796 KB |
Output is correct |
10 |
Correct |
3 ms |
8708 KB |
Output is correct |
11 |
Correct |
2 ms |
8676 KB |
Output is correct |
12 |
Correct |
2 ms |
8704 KB |
Output is correct |
13 |
Correct |
2 ms |
8672 KB |
Output is correct |
14 |
Correct |
2 ms |
8672 KB |
Output is correct |
15 |
Correct |
1 ms |
8540 KB |
Output is correct |
16 |
Correct |
1 ms |
6612 KB |
Output is correct |
17 |
Correct |
76 ms |
20268 KB |
Output is correct |
18 |
Correct |
69 ms |
18784 KB |
Output is correct |
19 |
Correct |
70 ms |
20040 KB |
Output is correct |
20 |
Correct |
72 ms |
20676 KB |
Output is correct |
21 |
Correct |
75 ms |
20676 KB |
Output is correct |
22 |
Correct |
80 ms |
19856 KB |
Output is correct |
23 |
Correct |
82 ms |
20160 KB |
Output is correct |
24 |
Correct |
55 ms |
20028 KB |
Output is correct |
25 |
Correct |
63 ms |
20672 KB |
Output is correct |
26 |
Correct |
59 ms |
20416 KB |
Output is correct |
27 |
Correct |
55 ms |
19640 KB |
Output is correct |
28 |
Correct |
62 ms |
19764 KB |
Output is correct |
29 |
Correct |
70 ms |
20796 KB |
Output is correct |
30 |
Correct |
54 ms |
19612 KB |
Output is correct |
31 |
Correct |
1 ms |
6492 KB |
Output is correct |
32 |
Correct |
74 ms |
20288 KB |
Output is correct |
33 |
Correct |
80 ms |
20400 KB |
Output is correct |
34 |
Correct |
64 ms |
20160 KB |
Output is correct |
35 |
Correct |
55 ms |
19168 KB |
Output is correct |
36 |
Correct |
93 ms |
19548 KB |
Output is correct |
37 |
Correct |
75 ms |
20692 KB |
Output is correct |
38 |
Correct |
77 ms |
19712 KB |
Output is correct |
39 |
Correct |
60 ms |
20400 KB |
Output is correct |
40 |
Correct |
61 ms |
19652 KB |
Output is correct |
41 |
Correct |
59 ms |
19056 KB |
Output is correct |
42 |
Correct |
1 ms |
6492 KB |
Output is correct |
43 |
Correct |
87 ms |
21260 KB |
Output is correct |
44 |
Correct |
71 ms |
21420 KB |
Output is correct |
45 |
Correct |
75 ms |
21076 KB |
Output is correct |
46 |
Correct |
69 ms |
21048 KB |
Output is correct |
47 |
Correct |
68 ms |
20932 KB |
Output is correct |
48 |
Correct |
66 ms |
21308 KB |
Output is correct |
49 |
Correct |
55 ms |
19848 KB |
Output is correct |
50 |
Correct |
64 ms |
18628 KB |
Output is correct |
51 |
Correct |
70 ms |
18992 KB |
Output is correct |
52 |
Correct |
64 ms |
19516 KB |
Output is correct |
53 |
Correct |
1 ms |
8540 KB |
Output is correct |
54 |
Correct |
1 ms |
8540 KB |
Output is correct |
55 |
Correct |
1 ms |
6488 KB |
Output is correct |
56 |
Correct |
2 ms |
8796 KB |
Output is correct |
57 |
Correct |
2 ms |
8796 KB |
Output is correct |
58 |
Correct |
2 ms |
8796 KB |
Output is correct |
59 |
Correct |
2 ms |
8796 KB |
Output is correct |
60 |
Correct |
2 ms |
8796 KB |
Output is correct |
61 |
Correct |
2 ms |
8796 KB |
Output is correct |
62 |
Correct |
2 ms |
8796 KB |
Output is correct |
63 |
Correct |
2 ms |
8796 KB |
Output is correct |
64 |
Correct |
2 ms |
8792 KB |
Output is correct |
65 |
Correct |
2 ms |
8796 KB |
Output is correct |
66 |
Correct |
2 ms |
8796 KB |
Output is correct |
67 |
Correct |
71 ms |
20768 KB |
Output is correct |
68 |
Correct |
61 ms |
20148 KB |
Output is correct |
69 |
Correct |
68 ms |
20396 KB |
Output is correct |
70 |
Correct |
89 ms |
20672 KB |
Output is correct |
71 |
Correct |
82 ms |
20464 KB |
Output is correct |
72 |
Correct |
73 ms |
19908 KB |
Output is correct |
73 |
Correct |
67 ms |
19396 KB |
Output is correct |
74 |
Correct |
58 ms |
20416 KB |
Output is correct |
75 |
Correct |
78 ms |
20916 KB |
Output is correct |
76 |
Correct |
76 ms |
20848 KB |
Output is correct |
77 |
Correct |
68 ms |
19956 KB |
Output is correct |
78 |
Correct |
62 ms |
19776 KB |
Output is correct |
79 |
Correct |
91 ms |
21392 KB |
Output is correct |
80 |
Correct |
59 ms |
19364 KB |
Output is correct |
81 |
Correct |
74 ms |
21088 KB |
Output is correct |
82 |
Correct |
83 ms |
20940 KB |
Output is correct |
83 |
Correct |
68 ms |
19912 KB |
Output is correct |
84 |
Correct |
56 ms |
19080 KB |
Output is correct |
85 |
Correct |
88 ms |
17276 KB |
Output is correct |
86 |
Correct |
67 ms |
18440 KB |
Output is correct |
87 |
Correct |
87 ms |
17860 KB |
Output is correct |
88 |
Correct |
68 ms |
17088 KB |
Output is correct |
89 |
Correct |
59 ms |
18912 KB |
Output is correct |
90 |
Correct |
71 ms |
18112 KB |
Output is correct |
91 |
Correct |
75 ms |
17448 KB |
Output is correct |
92 |
Correct |
79 ms |
18368 KB |
Output is correct |
93 |
Correct |
83 ms |
18116 KB |
Output is correct |
94 |
Correct |
78 ms |
18116 KB |
Output is correct |
95 |
Correct |
65 ms |
19384 KB |
Output is correct |
96 |
Correct |
59 ms |
17560 KB |
Output is correct |
97 |
Correct |
58 ms |
17856 KB |
Output is correct |
98 |
Correct |
59 ms |
18624 KB |
Output is correct |
99 |
Correct |
58 ms |
17084 KB |
Output is correct |
100 |
Correct |
41 ms |
18124 KB |
Output is correct |
101 |
Correct |
82 ms |
18628 KB |
Output is correct |
102 |
Correct |
75 ms |
17596 KB |
Output is correct |
103 |
Correct |
84 ms |
18240 KB |
Output is correct |
104 |
Correct |
80 ms |
18376 KB |
Output is correct |