#include<bits/stdc++.h>
using namespace std;
#define all(fl) fl.begin(),fl.end()
#define pb push_back
#define fi first
#define se second
#define for1(i,j,k) for(int i=j;i<=k;i++)
#define for2(i,j,k) for(int i=j;i>=k;i--)
#define for3(i,j,k,l) for(int i=j;i<=k;i+=l)
#define lb lower_bound
#define ub upper_bound
#define sz(a) (int)a.size()
#define gcd __gcd
#define lcm(x,y) x*y/__gcd(x,y)
using pii=pair<int,int>;
using pli=pair<long long,int>;
using pil=pair<int,long long>;
using pll=pair<long long,long long>;
const int maxn=2e5+9;
int lab[maxn*2];
vector<int>a[maxn*2];
int findset(int u){
if (lab[u]==u)return u;
return lab[u]=findset(lab[u]);
}
int nnode=0;
int n,m;
int mx[maxn*2];
void unite(int u,int v,int w){
u=findset(u),v=findset(v);
if (u==v)return;
nnode++;
lab[nnode]=nnode;
a[nnode].pb(u);
a[nnode].pb(v);
mx[nnode]=w;
lab[u]=nnode;
lab[v]=nnode;
}
int b[maxn];
int d[maxn];
struct edg{
int u,v;
bool operator <(const edg &p)const {
return max(b[u],b[v])<max(b[p.u],b[p.v]);
}
}c[maxn];
long long sub[maxn*2];
int st[maxn*2][21];
void dfs(int u){
for (auto v:a[u]){
st[v][0]=u;
for1(j,1,20){
st[v][j]=st[st[v][j-1]][j-1];
}
dfs(v);
sub[u]+=sub[v];
}
}
signed main(){
srand(time(0));
ios_base::sync_with_stdio(0);
cin.tie(0);
//freopen("usaco.INP","r",stdin);
//freopen("usaco.OUT","w",stdout);
cin>>n>>m;
for1(i,1,n){
cin>>b[i];
lab[i]=i;
d[i]=b[i];
mx[i]=b[i];
sub[i]+=b[i];
}
sort(d+1,d+1+n);
for1(i,1,m){
cin>>c[i].u>>c[i].v;
}
sort(c+1,c+1+m);
nnode=n;
for1(i,1,m){
unite(c[i].u,c[i].v,max(b[c[i].u],b[c[i].v]));
}
dfs(nnode);
for1(i,1,n){
long long nn=b[i];
bool fl=false;
while (true){
//cerr<<nn<<'\n';
int id=upper_bound(d+1,d+1+n,nn)-d;
if (id==1+n){
fl=true;
break;
}
int kaka=i;
for2(j,20,0){
if (st[kaka][j]==0)continue;
if (mx[st[kaka][j]]<=nn){
kaka=st[kaka][j];
}
}
//cout<<sub[kaka]<<'\n';
long long newsum=sub[kaka];
int id2=upper_bound(d+1,d+1+n,newsum)-d;
if (id==id2){
break;
}
nn=newsum;
}
cout<<fl;
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
5 ms |
9728 KB |
Output is correct |
3 |
Correct |
5 ms |
9684 KB |
Output is correct |
4 |
Correct |
6 ms |
10196 KB |
Output is correct |
5 |
Correct |
7 ms |
10260 KB |
Output is correct |
6 |
Correct |
6 ms |
10068 KB |
Output is correct |
7 |
Correct |
7 ms |
10236 KB |
Output is correct |
8 |
Correct |
6 ms |
10124 KB |
Output is correct |
9 |
Correct |
6 ms |
10336 KB |
Output is correct |
10 |
Correct |
7 ms |
10196 KB |
Output is correct |
11 |
Correct |
6 ms |
10196 KB |
Output is correct |
12 |
Correct |
7 ms |
10196 KB |
Output is correct |
13 |
Correct |
6 ms |
10196 KB |
Output is correct |
14 |
Correct |
6 ms |
10260 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
5 ms |
9684 KB |
Output is correct |
3 |
Correct |
222 ms |
70944 KB |
Output is correct |
4 |
Correct |
200 ms |
61456 KB |
Output is correct |
5 |
Correct |
288 ms |
61164 KB |
Output is correct |
6 |
Correct |
288 ms |
62668 KB |
Output is correct |
7 |
Correct |
298 ms |
62832 KB |
Output is correct |
8 |
Correct |
264 ms |
62796 KB |
Output is correct |
9 |
Correct |
194 ms |
62644 KB |
Output is correct |
10 |
Correct |
226 ms |
77568 KB |
Output is correct |
11 |
Correct |
181 ms |
77536 KB |
Output is correct |
12 |
Correct |
262 ms |
61436 KB |
Output is correct |
13 |
Correct |
195 ms |
61288 KB |
Output is correct |
14 |
Correct |
194 ms |
61460 KB |
Output is correct |
15 |
Correct |
193 ms |
78456 KB |
Output is correct |
16 |
Correct |
173 ms |
77060 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
288 ms |
62576 KB |
Output is correct |
3 |
Correct |
290 ms |
62852 KB |
Output is correct |
4 |
Correct |
193 ms |
62880 KB |
Output is correct |
5 |
Correct |
218 ms |
61312 KB |
Output is correct |
6 |
Correct |
285 ms |
62792 KB |
Output is correct |
7 |
Correct |
204 ms |
78540 KB |
Output is correct |
8 |
Correct |
236 ms |
78540 KB |
Output is correct |
9 |
Correct |
179 ms |
77108 KB |
Output is correct |
10 |
Correct |
211 ms |
62192 KB |
Output is correct |
11 |
Correct |
221 ms |
61324 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9660 KB |
Output is correct |
2 |
Correct |
304 ms |
63664 KB |
Output is correct |
3 |
Correct |
306 ms |
62804 KB |
Output is correct |
4 |
Correct |
293 ms |
62840 KB |
Output is correct |
5 |
Correct |
249 ms |
63020 KB |
Output is correct |
6 |
Correct |
228 ms |
62160 KB |
Output is correct |
7 |
Correct |
228 ms |
78468 KB |
Output is correct |
8 |
Correct |
175 ms |
69624 KB |
Output is correct |
9 |
Correct |
166 ms |
38076 KB |
Output is correct |
10 |
Correct |
249 ms |
61348 KB |
Output is correct |
11 |
Correct |
232 ms |
61448 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
5 ms |
9728 KB |
Output is correct |
3 |
Correct |
5 ms |
9684 KB |
Output is correct |
4 |
Correct |
6 ms |
10196 KB |
Output is correct |
5 |
Correct |
7 ms |
10260 KB |
Output is correct |
6 |
Correct |
6 ms |
10068 KB |
Output is correct |
7 |
Correct |
7 ms |
10236 KB |
Output is correct |
8 |
Correct |
6 ms |
10124 KB |
Output is correct |
9 |
Correct |
6 ms |
10336 KB |
Output is correct |
10 |
Correct |
7 ms |
10196 KB |
Output is correct |
11 |
Correct |
6 ms |
10196 KB |
Output is correct |
12 |
Correct |
7 ms |
10196 KB |
Output is correct |
13 |
Correct |
6 ms |
10196 KB |
Output is correct |
14 |
Correct |
6 ms |
10260 KB |
Output is correct |
15 |
Correct |
5 ms |
9684 KB |
Output is correct |
16 |
Correct |
5 ms |
9684 KB |
Output is correct |
17 |
Correct |
222 ms |
70944 KB |
Output is correct |
18 |
Correct |
200 ms |
61456 KB |
Output is correct |
19 |
Correct |
288 ms |
61164 KB |
Output is correct |
20 |
Correct |
288 ms |
62668 KB |
Output is correct |
21 |
Correct |
298 ms |
62832 KB |
Output is correct |
22 |
Correct |
264 ms |
62796 KB |
Output is correct |
23 |
Correct |
194 ms |
62644 KB |
Output is correct |
24 |
Correct |
226 ms |
77568 KB |
Output is correct |
25 |
Correct |
181 ms |
77536 KB |
Output is correct |
26 |
Correct |
262 ms |
61436 KB |
Output is correct |
27 |
Correct |
195 ms |
61288 KB |
Output is correct |
28 |
Correct |
194 ms |
61460 KB |
Output is correct |
29 |
Correct |
193 ms |
78456 KB |
Output is correct |
30 |
Correct |
173 ms |
77060 KB |
Output is correct |
31 |
Correct |
5 ms |
9684 KB |
Output is correct |
32 |
Correct |
288 ms |
62576 KB |
Output is correct |
33 |
Correct |
290 ms |
62852 KB |
Output is correct |
34 |
Correct |
193 ms |
62880 KB |
Output is correct |
35 |
Correct |
218 ms |
61312 KB |
Output is correct |
36 |
Correct |
285 ms |
62792 KB |
Output is correct |
37 |
Correct |
204 ms |
78540 KB |
Output is correct |
38 |
Correct |
236 ms |
78540 KB |
Output is correct |
39 |
Correct |
179 ms |
77108 KB |
Output is correct |
40 |
Correct |
211 ms |
62192 KB |
Output is correct |
41 |
Correct |
221 ms |
61324 KB |
Output is correct |
42 |
Correct |
5 ms |
9660 KB |
Output is correct |
43 |
Correct |
304 ms |
63664 KB |
Output is correct |
44 |
Correct |
306 ms |
62804 KB |
Output is correct |
45 |
Correct |
293 ms |
62840 KB |
Output is correct |
46 |
Correct |
249 ms |
63020 KB |
Output is correct |
47 |
Correct |
228 ms |
62160 KB |
Output is correct |
48 |
Correct |
228 ms |
78468 KB |
Output is correct |
49 |
Correct |
175 ms |
69624 KB |
Output is correct |
50 |
Correct |
166 ms |
38076 KB |
Output is correct |
51 |
Correct |
249 ms |
61348 KB |
Output is correct |
52 |
Correct |
232 ms |
61448 KB |
Output is correct |
53 |
Correct |
5 ms |
9684 KB |
Output is correct |
54 |
Correct |
4 ms |
9684 KB |
Output is correct |
55 |
Correct |
4 ms |
9732 KB |
Output is correct |
56 |
Correct |
6 ms |
10196 KB |
Output is correct |
57 |
Correct |
6 ms |
10196 KB |
Output is correct |
58 |
Correct |
6 ms |
10080 KB |
Output is correct |
59 |
Correct |
6 ms |
10196 KB |
Output is correct |
60 |
Correct |
6 ms |
10068 KB |
Output is correct |
61 |
Correct |
7 ms |
10332 KB |
Output is correct |
62 |
Correct |
6 ms |
10260 KB |
Output is correct |
63 |
Correct |
6 ms |
10256 KB |
Output is correct |
64 |
Correct |
6 ms |
10196 KB |
Output is correct |
65 |
Correct |
6 ms |
10260 KB |
Output is correct |
66 |
Correct |
6 ms |
10196 KB |
Output is correct |
67 |
Correct |
222 ms |
70956 KB |
Output is correct |
68 |
Correct |
191 ms |
61408 KB |
Output is correct |
69 |
Correct |
277 ms |
61144 KB |
Output is correct |
70 |
Correct |
324 ms |
62712 KB |
Output is correct |
71 |
Correct |
288 ms |
62836 KB |
Output is correct |
72 |
Correct |
276 ms |
62876 KB |
Output is correct |
73 |
Correct |
172 ms |
62740 KB |
Output is correct |
74 |
Correct |
267 ms |
77624 KB |
Output is correct |
75 |
Correct |
192 ms |
77500 KB |
Output is correct |
76 |
Correct |
259 ms |
61372 KB |
Output is correct |
77 |
Correct |
193 ms |
61284 KB |
Output is correct |
78 |
Correct |
191 ms |
61564 KB |
Output is correct |
79 |
Correct |
187 ms |
78504 KB |
Output is correct |
80 |
Correct |
200 ms |
77136 KB |
Output is correct |
81 |
Correct |
280 ms |
62456 KB |
Output is correct |
82 |
Correct |
314 ms |
62860 KB |
Output is correct |
83 |
Correct |
203 ms |
62888 KB |
Output is correct |
84 |
Correct |
210 ms |
61296 KB |
Output is correct |
85 |
Correct |
286 ms |
62876 KB |
Output is correct |
86 |
Correct |
210 ms |
78552 KB |
Output is correct |
87 |
Correct |
226 ms |
78460 KB |
Output is correct |
88 |
Correct |
207 ms |
62116 KB |
Output is correct |
89 |
Correct |
234 ms |
61412 KB |
Output is correct |
90 |
Correct |
301 ms |
63720 KB |
Output is correct |
91 |
Correct |
297 ms |
62848 KB |
Output is correct |
92 |
Correct |
300 ms |
62888 KB |
Output is correct |
93 |
Correct |
256 ms |
62864 KB |
Output is correct |
94 |
Correct |
241 ms |
62164 KB |
Output is correct |
95 |
Correct |
266 ms |
78448 KB |
Output is correct |
96 |
Correct |
178 ms |
69520 KB |
Output is correct |
97 |
Correct |
179 ms |
38136 KB |
Output is correct |
98 |
Correct |
272 ms |
61348 KB |
Output is correct |
99 |
Correct |
248 ms |
61380 KB |
Output is correct |
100 |
Correct |
55 ms |
14428 KB |
Output is correct |
101 |
Correct |
388 ms |
63044 KB |
Output is correct |
102 |
Correct |
199 ms |
55036 KB |
Output is correct |
103 |
Correct |
367 ms |
60092 KB |
Output is correct |
104 |
Correct |
389 ms |
64224 KB |
Output is correct |