#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using ll = long long;
using ld = long double;
void solve(int T);
void pre();
const int N = 2e5 + 10;
const int M = 405;
const int SQRT = 500;
const int LOG = 20;
const int INF = 1e18;
const int MOD = 1e9+7;
const ld EPS = 1e-9;
void pre(){
#ifdef ONLINE_JUDGE
ios::sync_with_stdio(false);
cin.tie(0);
#endif
}
int32_t main(){
pre();
int tt = 1;
//cin>>tt;
for(int i = 1;i<=tt;i++){
//cerr<<"Case "<<i<<": "<<endl;
solve(i);
}
return 0;
}
struct Edge{
int u,v,w;
};
bool operator<(Edge a,Edge b){
return a.w < b.w;
}
bool bad[N];
int A[N];
int sum[N];
int p[N];
int find(int u){
if(p[u] == u)return u;
int v = find(p[u]);
bad[u] |= bad[p[u]];
p[u] = v;
return v;
}
void join(int u,int v){
u = find(u);
v = find(v);
if(u == v)return;
if(A[u] < A[v])swap(u,v);
if(A[u] > sum[v])bad[v] = true;
p[v] = u;
sum[u] += sum[v];
}
void solve(int T){
int n,m;
cin>>n>>m;
for(int i = 1;i<=n;i++){
cin>>A[i];
p[i] = i;
sum[i] = A[i];
}
Edge edge[m];
for(int i = 0;i<m;i++){
int u,v;
cin>>u>>v;
edge[i] = {u, v, max(A[u], A[v])};
}
sort(edge, edge + m);
for(auto p : edge){
join(p.u, p.v);
}
cerr<<"kur"<<endl;
for(int i = 1;i<=n;i++){
find(i);
cout<<!bad[i];
}
cout<<endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
2 ms |
4556 KB |
Output is correct |
5 |
Correct |
2 ms |
4444 KB |
Output is correct |
6 |
Correct |
2 ms |
4444 KB |
Output is correct |
7 |
Correct |
2 ms |
4440 KB |
Output is correct |
8 |
Correct |
2 ms |
4444 KB |
Output is correct |
9 |
Correct |
2 ms |
4444 KB |
Output is correct |
10 |
Correct |
2 ms |
4452 KB |
Output is correct |
11 |
Correct |
2 ms |
4552 KB |
Output is correct |
12 |
Correct |
2 ms |
4444 KB |
Output is correct |
13 |
Correct |
2 ms |
4444 KB |
Output is correct |
14 |
Correct |
2 ms |
4444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4540 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
172 ms |
14620 KB |
Output is correct |
4 |
Correct |
128 ms |
13252 KB |
Output is correct |
5 |
Correct |
155 ms |
14164 KB |
Output is correct |
6 |
Correct |
162 ms |
14420 KB |
Output is correct |
7 |
Correct |
159 ms |
14416 KB |
Output is correct |
8 |
Correct |
156 ms |
14416 KB |
Output is correct |
9 |
Correct |
162 ms |
14300 KB |
Output is correct |
10 |
Correct |
135 ms |
13768 KB |
Output is correct |
11 |
Correct |
132 ms |
14924 KB |
Output is correct |
12 |
Correct |
129 ms |
13140 KB |
Output is correct |
13 |
Correct |
119 ms |
12884 KB |
Output is correct |
14 |
Correct |
122 ms |
13140 KB |
Output is correct |
15 |
Correct |
158 ms |
14404 KB |
Output is correct |
16 |
Correct |
135 ms |
13648 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
167 ms |
12884 KB |
Output is correct |
3 |
Correct |
162 ms |
14420 KB |
Output is correct |
4 |
Correct |
154 ms |
14676 KB |
Output is correct |
5 |
Correct |
118 ms |
12884 KB |
Output is correct |
6 |
Correct |
171 ms |
14420 KB |
Output is correct |
7 |
Correct |
159 ms |
14524 KB |
Output is correct |
8 |
Correct |
177 ms |
14532 KB |
Output is correct |
9 |
Correct |
136 ms |
13644 KB |
Output is correct |
10 |
Correct |
138 ms |
13904 KB |
Output is correct |
11 |
Correct |
127 ms |
13136 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
160 ms |
12968 KB |
Output is correct |
3 |
Correct |
159 ms |
13908 KB |
Output is correct |
4 |
Correct |
168 ms |
14160 KB |
Output is correct |
5 |
Correct |
156 ms |
13824 KB |
Output is correct |
6 |
Correct |
153 ms |
13372 KB |
Output is correct |
7 |
Correct |
154 ms |
15696 KB |
Output is correct |
8 |
Correct |
128 ms |
12880 KB |
Output is correct |
9 |
Correct |
114 ms |
12112 KB |
Output is correct |
10 |
Correct |
122 ms |
12920 KB |
Output is correct |
11 |
Correct |
124 ms |
13260 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
2 ms |
4556 KB |
Output is correct |
5 |
Correct |
2 ms |
4444 KB |
Output is correct |
6 |
Correct |
2 ms |
4444 KB |
Output is correct |
7 |
Correct |
2 ms |
4440 KB |
Output is correct |
8 |
Correct |
2 ms |
4444 KB |
Output is correct |
9 |
Correct |
2 ms |
4444 KB |
Output is correct |
10 |
Correct |
2 ms |
4452 KB |
Output is correct |
11 |
Correct |
2 ms |
4552 KB |
Output is correct |
12 |
Correct |
2 ms |
4444 KB |
Output is correct |
13 |
Correct |
2 ms |
4444 KB |
Output is correct |
14 |
Correct |
2 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4540 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
172 ms |
14620 KB |
Output is correct |
18 |
Correct |
128 ms |
13252 KB |
Output is correct |
19 |
Correct |
155 ms |
14164 KB |
Output is correct |
20 |
Correct |
162 ms |
14420 KB |
Output is correct |
21 |
Correct |
159 ms |
14416 KB |
Output is correct |
22 |
Correct |
156 ms |
14416 KB |
Output is correct |
23 |
Correct |
162 ms |
14300 KB |
Output is correct |
24 |
Correct |
135 ms |
13768 KB |
Output is correct |
25 |
Correct |
132 ms |
14924 KB |
Output is correct |
26 |
Correct |
129 ms |
13140 KB |
Output is correct |
27 |
Correct |
119 ms |
12884 KB |
Output is correct |
28 |
Correct |
122 ms |
13140 KB |
Output is correct |
29 |
Correct |
158 ms |
14404 KB |
Output is correct |
30 |
Correct |
135 ms |
13648 KB |
Output is correct |
31 |
Correct |
1 ms |
4444 KB |
Output is correct |
32 |
Correct |
167 ms |
12884 KB |
Output is correct |
33 |
Correct |
162 ms |
14420 KB |
Output is correct |
34 |
Correct |
154 ms |
14676 KB |
Output is correct |
35 |
Correct |
118 ms |
12884 KB |
Output is correct |
36 |
Correct |
171 ms |
14420 KB |
Output is correct |
37 |
Correct |
159 ms |
14524 KB |
Output is correct |
38 |
Correct |
177 ms |
14532 KB |
Output is correct |
39 |
Correct |
136 ms |
13644 KB |
Output is correct |
40 |
Correct |
138 ms |
13904 KB |
Output is correct |
41 |
Correct |
127 ms |
13136 KB |
Output is correct |
42 |
Correct |
1 ms |
4444 KB |
Output is correct |
43 |
Correct |
160 ms |
12968 KB |
Output is correct |
44 |
Correct |
159 ms |
13908 KB |
Output is correct |
45 |
Correct |
168 ms |
14160 KB |
Output is correct |
46 |
Correct |
156 ms |
13824 KB |
Output is correct |
47 |
Correct |
153 ms |
13372 KB |
Output is correct |
48 |
Correct |
154 ms |
15696 KB |
Output is correct |
49 |
Correct |
128 ms |
12880 KB |
Output is correct |
50 |
Correct |
114 ms |
12112 KB |
Output is correct |
51 |
Correct |
122 ms |
12920 KB |
Output is correct |
52 |
Correct |
124 ms |
13260 KB |
Output is correct |
53 |
Correct |
1 ms |
4444 KB |
Output is correct |
54 |
Correct |
1 ms |
4444 KB |
Output is correct |
55 |
Correct |
1 ms |
4444 KB |
Output is correct |
56 |
Correct |
2 ms |
4444 KB |
Output is correct |
57 |
Correct |
2 ms |
4444 KB |
Output is correct |
58 |
Correct |
2 ms |
4444 KB |
Output is correct |
59 |
Correct |
2 ms |
4444 KB |
Output is correct |
60 |
Correct |
2 ms |
4444 KB |
Output is correct |
61 |
Correct |
2 ms |
4444 KB |
Output is correct |
62 |
Correct |
2 ms |
4444 KB |
Output is correct |
63 |
Correct |
2 ms |
4444 KB |
Output is correct |
64 |
Correct |
2 ms |
4444 KB |
Output is correct |
65 |
Correct |
2 ms |
4444 KB |
Output is correct |
66 |
Correct |
2 ms |
4444 KB |
Output is correct |
67 |
Correct |
169 ms |
14520 KB |
Output is correct |
68 |
Correct |
126 ms |
13244 KB |
Output is correct |
69 |
Correct |
153 ms |
14060 KB |
Output is correct |
70 |
Correct |
158 ms |
14352 KB |
Output is correct |
71 |
Correct |
162 ms |
14544 KB |
Output is correct |
72 |
Correct |
156 ms |
14416 KB |
Output is correct |
73 |
Correct |
157 ms |
14480 KB |
Output is correct |
74 |
Correct |
134 ms |
13632 KB |
Output is correct |
75 |
Correct |
133 ms |
14908 KB |
Output is correct |
76 |
Correct |
125 ms |
13116 KB |
Output is correct |
77 |
Correct |
119 ms |
12984 KB |
Output is correct |
78 |
Correct |
127 ms |
13244 KB |
Output is correct |
79 |
Correct |
160 ms |
14416 KB |
Output is correct |
80 |
Correct |
133 ms |
13816 KB |
Output is correct |
81 |
Correct |
183 ms |
14436 KB |
Output is correct |
82 |
Correct |
164 ms |
14424 KB |
Output is correct |
83 |
Correct |
152 ms |
14468 KB |
Output is correct |
84 |
Correct |
118 ms |
12992 KB |
Output is correct |
85 |
Correct |
168 ms |
14504 KB |
Output is correct |
86 |
Correct |
157 ms |
14664 KB |
Output is correct |
87 |
Correct |
167 ms |
14524 KB |
Output is correct |
88 |
Correct |
149 ms |
14160 KB |
Output is correct |
89 |
Correct |
133 ms |
13012 KB |
Output is correct |
90 |
Correct |
160 ms |
14416 KB |
Output is correct |
91 |
Correct |
160 ms |
14672 KB |
Output is correct |
92 |
Correct |
158 ms |
14552 KB |
Output is correct |
93 |
Correct |
156 ms |
14420 KB |
Output is correct |
94 |
Correct |
151 ms |
14164 KB |
Output is correct |
95 |
Correct |
154 ms |
16316 KB |
Output is correct |
96 |
Correct |
127 ms |
13392 KB |
Output is correct |
97 |
Correct |
113 ms |
12116 KB |
Output is correct |
98 |
Correct |
130 ms |
13396 KB |
Output is correct |
99 |
Correct |
144 ms |
13036 KB |
Output is correct |
100 |
Correct |
83 ms |
11036 KB |
Output is correct |
101 |
Correct |
169 ms |
14508 KB |
Output is correct |
102 |
Correct |
143 ms |
13644 KB |
Output is correct |
103 |
Correct |
164 ms |
13908 KB |
Output is correct |
104 |
Correct |
169 ms |
14416 KB |
Output is correct |