#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';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
8536 KB |
Output is correct |
2 |
Correct |
4 ms |
8540 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 |
8796 KB |
Output is correct |
6 |
Correct |
2 ms |
8692 KB |
Output is correct |
7 |
Correct |
2 ms |
8796 KB |
Output is correct |
8 |
Correct |
2 ms |
8796 KB |
Output is correct |
9 |
Correct |
2 ms |
8796 KB |
Output is correct |
10 |
Correct |
2 ms |
8796 KB |
Output is correct |
11 |
Correct |
3 ms |
8804 KB |
Output is correct |
12 |
Correct |
3 ms |
8796 KB |
Output is correct |
13 |
Correct |
2 ms |
8796 KB |
Output is correct |
14 |
Correct |
2 ms |
8796 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
8536 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
73 ms |
22448 KB |
Output is correct |
4 |
Correct |
59 ms |
20672 KB |
Output is correct |
5 |
Correct |
81 ms |
22192 KB |
Output is correct |
6 |
Correct |
74 ms |
22468 KB |
Output is correct |
7 |
Correct |
90 ms |
22072 KB |
Output is correct |
8 |
Correct |
75 ms |
21936 KB |
Output is correct |
9 |
Correct |
75 ms |
22596 KB |
Output is correct |
10 |
Correct |
59 ms |
20772 KB |
Output is correct |
11 |
Correct |
71 ms |
22712 KB |
Output is correct |
12 |
Correct |
62 ms |
20576 KB |
Output is correct |
13 |
Correct |
71 ms |
20588 KB |
Output is correct |
14 |
Correct |
59 ms |
20924 KB |
Output is correct |
15 |
Correct |
70 ms |
21784 KB |
Output is correct |
16 |
Correct |
56 ms |
21208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Correct |
78 ms |
22200 KB |
Output is correct |
3 |
Correct |
76 ms |
21860 KB |
Output is correct |
4 |
Correct |
63 ms |
21696 KB |
Output is correct |
5 |
Correct |
58 ms |
20280 KB |
Output is correct |
6 |
Correct |
77 ms |
22244 KB |
Output is correct |
7 |
Correct |
70 ms |
22592 KB |
Output is correct |
8 |
Correct |
74 ms |
21848 KB |
Output is correct |
9 |
Correct |
54 ms |
21908 KB |
Output is correct |
10 |
Correct |
61 ms |
21440 KB |
Output is correct |
11 |
Correct |
86 ms |
21004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
81 ms |
22148 KB |
Output is correct |
3 |
Correct |
77 ms |
22076 KB |
Output is correct |
4 |
Correct |
77 ms |
22364 KB |
Output is correct |
5 |
Correct |
77 ms |
22452 KB |
Output is correct |
6 |
Correct |
74 ms |
21736 KB |
Output is correct |
7 |
Correct |
97 ms |
23020 KB |
Output is correct |
8 |
Correct |
67 ms |
20928 KB |
Output is correct |
9 |
Correct |
73 ms |
19636 KB |
Output is correct |
10 |
Correct |
65 ms |
20416 KB |
Output is correct |
11 |
Correct |
59 ms |
20144 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
8536 KB |
Output is correct |
2 |
Correct |
4 ms |
8540 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 |
8796 KB |
Output is correct |
6 |
Correct |
2 ms |
8692 KB |
Output is correct |
7 |
Correct |
2 ms |
8796 KB |
Output is correct |
8 |
Correct |
2 ms |
8796 KB |
Output is correct |
9 |
Correct |
2 ms |
8796 KB |
Output is correct |
10 |
Correct |
2 ms |
8796 KB |
Output is correct |
11 |
Correct |
3 ms |
8804 KB |
Output is correct |
12 |
Correct |
3 ms |
8796 KB |
Output is correct |
13 |
Correct |
2 ms |
8796 KB |
Output is correct |
14 |
Correct |
2 ms |
8796 KB |
Output is correct |
15 |
Correct |
1 ms |
8536 KB |
Output is correct |
16 |
Correct |
1 ms |
6492 KB |
Output is correct |
17 |
Correct |
73 ms |
22448 KB |
Output is correct |
18 |
Correct |
59 ms |
20672 KB |
Output is correct |
19 |
Correct |
81 ms |
22192 KB |
Output is correct |
20 |
Correct |
74 ms |
22468 KB |
Output is correct |
21 |
Correct |
90 ms |
22072 KB |
Output is correct |
22 |
Correct |
75 ms |
21936 KB |
Output is correct |
23 |
Correct |
75 ms |
22596 KB |
Output is correct |
24 |
Correct |
59 ms |
20772 KB |
Output is correct |
25 |
Correct |
71 ms |
22712 KB |
Output is correct |
26 |
Correct |
62 ms |
20576 KB |
Output is correct |
27 |
Correct |
71 ms |
20588 KB |
Output is correct |
28 |
Correct |
59 ms |
20924 KB |
Output is correct |
29 |
Correct |
70 ms |
21784 KB |
Output is correct |
30 |
Correct |
56 ms |
21208 KB |
Output is correct |
31 |
Correct |
1 ms |
6488 KB |
Output is correct |
32 |
Correct |
78 ms |
22200 KB |
Output is correct |
33 |
Correct |
76 ms |
21860 KB |
Output is correct |
34 |
Correct |
63 ms |
21696 KB |
Output is correct |
35 |
Correct |
58 ms |
20280 KB |
Output is correct |
36 |
Correct |
77 ms |
22244 KB |
Output is correct |
37 |
Correct |
70 ms |
22592 KB |
Output is correct |
38 |
Correct |
74 ms |
21848 KB |
Output is correct |
39 |
Correct |
54 ms |
21908 KB |
Output is correct |
40 |
Correct |
61 ms |
21440 KB |
Output is correct |
41 |
Correct |
86 ms |
21004 KB |
Output is correct |
42 |
Correct |
1 ms |
6492 KB |
Output is correct |
43 |
Correct |
81 ms |
22148 KB |
Output is correct |
44 |
Correct |
77 ms |
22076 KB |
Output is correct |
45 |
Correct |
77 ms |
22364 KB |
Output is correct |
46 |
Correct |
77 ms |
22452 KB |
Output is correct |
47 |
Correct |
74 ms |
21736 KB |
Output is correct |
48 |
Correct |
97 ms |
23020 KB |
Output is correct |
49 |
Correct |
67 ms |
20928 KB |
Output is correct |
50 |
Correct |
73 ms |
19636 KB |
Output is correct |
51 |
Correct |
65 ms |
20416 KB |
Output is correct |
52 |
Correct |
59 ms |
20144 KB |
Output is correct |
53 |
Correct |
2 ms |
8540 KB |
Output is correct |
54 |
Correct |
1 ms |
8540 KB |
Output is correct |
55 |
Correct |
1 ms |
6492 KB |
Output is correct |
56 |
Correct |
3 ms |
8796 KB |
Output is correct |
57 |
Correct |
2 ms |
8800 KB |
Output is correct |
58 |
Correct |
2 ms |
8836 KB |
Output is correct |
59 |
Correct |
2 ms |
8676 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 |
8676 KB |
Output is correct |
63 |
Correct |
2 ms |
8796 KB |
Output is correct |
64 |
Correct |
2 ms |
8796 KB |
Output is correct |
65 |
Correct |
2 ms |
8796 KB |
Output is correct |
66 |
Correct |
2 ms |
8796 KB |
Output is correct |
67 |
Correct |
72 ms |
22728 KB |
Output is correct |
68 |
Correct |
58 ms |
20428 KB |
Output is correct |
69 |
Correct |
76 ms |
21600 KB |
Output is correct |
70 |
Correct |
83 ms |
21448 KB |
Output is correct |
71 |
Correct |
90 ms |
21780 KB |
Output is correct |
72 |
Correct |
67 ms |
21936 KB |
Output is correct |
73 |
Correct |
75 ms |
21600 KB |
Output is correct |
74 |
Correct |
62 ms |
21256 KB |
Output is correct |
75 |
Correct |
62 ms |
21452 KB |
Output is correct |
76 |
Correct |
62 ms |
20088 KB |
Output is correct |
77 |
Correct |
63 ms |
20144 KB |
Output is correct |
78 |
Correct |
61 ms |
21356 KB |
Output is correct |
79 |
Correct |
75 ms |
22204 KB |
Output is correct |
80 |
Correct |
56 ms |
20628 KB |
Output is correct |
81 |
Correct |
76 ms |
21676 KB |
Output is correct |
82 |
Correct |
81 ms |
21912 KB |
Output is correct |
83 |
Correct |
82 ms |
22268 KB |
Output is correct |
84 |
Correct |
58 ms |
20160 KB |
Output is correct |
85 |
Correct |
90 ms |
21332 KB |
Output is correct |
86 |
Correct |
83 ms |
22132 KB |
Output is correct |
87 |
Correct |
73 ms |
21436 KB |
Output is correct |
88 |
Correct |
90 ms |
20836 KB |
Output is correct |
89 |
Correct |
78 ms |
20548 KB |
Output is correct |
90 |
Correct |
82 ms |
21700 KB |
Output is correct |
91 |
Correct |
76 ms |
22508 KB |
Output is correct |
92 |
Correct |
77 ms |
22120 KB |
Output is correct |
93 |
Correct |
73 ms |
22392 KB |
Output is correct |
94 |
Correct |
78 ms |
21300 KB |
Output is correct |
95 |
Correct |
82 ms |
23416 KB |
Output is correct |
96 |
Correct |
62 ms |
21308 KB |
Output is correct |
97 |
Correct |
62 ms |
20428 KB |
Output is correct |
98 |
Correct |
68 ms |
20360 KB |
Output is correct |
99 |
Correct |
87 ms |
20652 KB |
Output is correct |
100 |
Correct |
48 ms |
18704 KB |
Output is correct |
101 |
Correct |
88 ms |
20900 KB |
Output is correct |
102 |
Correct |
80 ms |
21924 KB |
Output is correct |
103 |
Correct |
85 ms |
20664 KB |
Output is correct |
104 |
Correct |
94 ms |
22224 KB |
Output is correct |