#include<bits/stdc++.h>
#define TASKNAME "codeforce"
#define pb push_back
#define pli pair<int,int>
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
using ll=long long;
const ll maxN=2e5+10;
const ll inf=1e18;
const ll mod=1e9+7;
ll lab[maxN];
ll sum[maxN];
ll findset(ll x)
{
return lab[x]<0?x:lab[x]=findset(lab[x]);
}
vector<ll>vec[maxN];
void unite(ll u,ll v,ll w)
{
u=findset(u);
v=findset(v);
if(u==v) return;
if(lab[u]>lab[v]) swap(u,v);
if(sum[u]<w)
{
if(sum[v]<w)
{
vec[u].clear();
}
else
{
swap(vec[u],vec[v]);
}
vec[v].clear();
}
else
{
if(sum[v]>=w)
{
for(auto zz:vec[v]) vec[u].pb(zz);
}
vec[v].clear();
}
sum[u]+=sum[v];
lab[u]+=lab[v];
lab[v]=u;
}
ll n,m,ans[maxN],a[maxN];
struct edge
{
ll u,v,w;
bool operator<(const edge&o)
{
return w<o.w;
}
}e[maxN];
void solve()
{
cin >> n >> m;
for(int i=1;i<=n;i++) cin >> a[i],vec[i].pb(i),ans[i]=0,sum[i]=a[i],lab[i]=-1;
for(int i=1;i<=m;i++)
{
cin >> e[i].u >> e[i].v;
e[i].w=max(a[e[i].u],a[e[i].v]);
}
sort(e+1,e+m+1);
for(int i=1;i<=m;i++)
{
unite(e[i].u,e[i].v,e[i].w);
}
ll x=findset(1);
for(auto zz:vec[x])
{
ans[zz]=1;
}
for(int i=1;i<=n;i++) cout << ans[i];
}
int main()
{
fastio
//freopen(TASKNAME".INP","r",stdin);
//freopen(TASKNAME".OUT","w",stdout);
solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
4 ms |
5040 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
4 ms |
5304 KB |
Output is correct |
5 |
Correct |
4 ms |
5300 KB |
Output is correct |
6 |
Correct |
4 ms |
5204 KB |
Output is correct |
7 |
Correct |
4 ms |
5204 KB |
Output is correct |
8 |
Correct |
3 ms |
5168 KB |
Output is correct |
9 |
Correct |
4 ms |
5176 KB |
Output is correct |
10 |
Correct |
4 ms |
5332 KB |
Output is correct |
11 |
Correct |
4 ms |
5332 KB |
Output is correct |
12 |
Correct |
4 ms |
5264 KB |
Output is correct |
13 |
Correct |
4 ms |
5308 KB |
Output is correct |
14 |
Correct |
4 ms |
5204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
3 ms |
4948 KB |
Output is correct |
3 |
Correct |
121 ms |
25664 KB |
Output is correct |
4 |
Correct |
141 ms |
36244 KB |
Output is correct |
5 |
Correct |
112 ms |
27956 KB |
Output is correct |
6 |
Correct |
120 ms |
28796 KB |
Output is correct |
7 |
Correct |
123 ms |
28800 KB |
Output is correct |
8 |
Correct |
150 ms |
33080 KB |
Output is correct |
9 |
Correct |
109 ms |
31820 KB |
Output is correct |
10 |
Correct |
93 ms |
23096 KB |
Output is correct |
11 |
Correct |
112 ms |
25252 KB |
Output is correct |
12 |
Correct |
144 ms |
27828 KB |
Output is correct |
13 |
Correct |
159 ms |
38668 KB |
Output is correct |
14 |
Correct |
147 ms |
37180 KB |
Output is correct |
15 |
Correct |
97 ms |
25152 KB |
Output is correct |
16 |
Correct |
78 ms |
25092 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
5036 KB |
Output is correct |
2 |
Correct |
139 ms |
30320 KB |
Output is correct |
3 |
Correct |
133 ms |
30604 KB |
Output is correct |
4 |
Correct |
149 ms |
38760 KB |
Output is correct |
5 |
Correct |
153 ms |
38412 KB |
Output is correct |
6 |
Correct |
135 ms |
30520 KB |
Output is correct |
7 |
Correct |
101 ms |
25152 KB |
Output is correct |
8 |
Correct |
96 ms |
25168 KB |
Output is correct |
9 |
Correct |
75 ms |
24924 KB |
Output is correct |
10 |
Correct |
119 ms |
30628 KB |
Output is correct |
11 |
Correct |
129 ms |
32532 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
124 ms |
26376 KB |
Output is correct |
3 |
Correct |
126 ms |
27332 KB |
Output is correct |
4 |
Correct |
165 ms |
28840 KB |
Output is correct |
5 |
Correct |
173 ms |
31644 KB |
Output is correct |
6 |
Correct |
133 ms |
28124 KB |
Output is correct |
7 |
Correct |
112 ms |
25148 KB |
Output is correct |
8 |
Correct |
90 ms |
28668 KB |
Output is correct |
9 |
Correct |
77 ms |
18228 KB |
Output is correct |
10 |
Correct |
139 ms |
32988 KB |
Output is correct |
11 |
Correct |
134 ms |
32068 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
4 ms |
5040 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Correct |
4 ms |
5304 KB |
Output is correct |
5 |
Correct |
4 ms |
5300 KB |
Output is correct |
6 |
Correct |
4 ms |
5204 KB |
Output is correct |
7 |
Correct |
4 ms |
5204 KB |
Output is correct |
8 |
Correct |
3 ms |
5168 KB |
Output is correct |
9 |
Correct |
4 ms |
5176 KB |
Output is correct |
10 |
Correct |
4 ms |
5332 KB |
Output is correct |
11 |
Correct |
4 ms |
5332 KB |
Output is correct |
12 |
Correct |
4 ms |
5264 KB |
Output is correct |
13 |
Correct |
4 ms |
5308 KB |
Output is correct |
14 |
Correct |
4 ms |
5204 KB |
Output is correct |
15 |
Correct |
3 ms |
4948 KB |
Output is correct |
16 |
Correct |
3 ms |
4948 KB |
Output is correct |
17 |
Correct |
121 ms |
25664 KB |
Output is correct |
18 |
Correct |
141 ms |
36244 KB |
Output is correct |
19 |
Correct |
112 ms |
27956 KB |
Output is correct |
20 |
Correct |
120 ms |
28796 KB |
Output is correct |
21 |
Correct |
123 ms |
28800 KB |
Output is correct |
22 |
Correct |
150 ms |
33080 KB |
Output is correct |
23 |
Correct |
109 ms |
31820 KB |
Output is correct |
24 |
Correct |
93 ms |
23096 KB |
Output is correct |
25 |
Correct |
112 ms |
25252 KB |
Output is correct |
26 |
Correct |
144 ms |
27828 KB |
Output is correct |
27 |
Correct |
159 ms |
38668 KB |
Output is correct |
28 |
Correct |
147 ms |
37180 KB |
Output is correct |
29 |
Correct |
97 ms |
25152 KB |
Output is correct |
30 |
Correct |
78 ms |
25092 KB |
Output is correct |
31 |
Correct |
3 ms |
5036 KB |
Output is correct |
32 |
Correct |
139 ms |
30320 KB |
Output is correct |
33 |
Correct |
133 ms |
30604 KB |
Output is correct |
34 |
Correct |
149 ms |
38760 KB |
Output is correct |
35 |
Correct |
153 ms |
38412 KB |
Output is correct |
36 |
Correct |
135 ms |
30520 KB |
Output is correct |
37 |
Correct |
101 ms |
25152 KB |
Output is correct |
38 |
Correct |
96 ms |
25168 KB |
Output is correct |
39 |
Correct |
75 ms |
24924 KB |
Output is correct |
40 |
Correct |
119 ms |
30628 KB |
Output is correct |
41 |
Correct |
129 ms |
32532 KB |
Output is correct |
42 |
Correct |
3 ms |
4948 KB |
Output is correct |
43 |
Correct |
124 ms |
26376 KB |
Output is correct |
44 |
Correct |
126 ms |
27332 KB |
Output is correct |
45 |
Correct |
165 ms |
28840 KB |
Output is correct |
46 |
Correct |
173 ms |
31644 KB |
Output is correct |
47 |
Correct |
133 ms |
28124 KB |
Output is correct |
48 |
Correct |
112 ms |
25148 KB |
Output is correct |
49 |
Correct |
90 ms |
28668 KB |
Output is correct |
50 |
Correct |
77 ms |
18228 KB |
Output is correct |
51 |
Correct |
139 ms |
32988 KB |
Output is correct |
52 |
Correct |
134 ms |
32068 KB |
Output is correct |
53 |
Correct |
3 ms |
4948 KB |
Output is correct |
54 |
Correct |
3 ms |
4948 KB |
Output is correct |
55 |
Correct |
3 ms |
4948 KB |
Output is correct |
56 |
Correct |
4 ms |
5176 KB |
Output is correct |
57 |
Correct |
4 ms |
5440 KB |
Output is correct |
58 |
Correct |
5 ms |
5236 KB |
Output is correct |
59 |
Correct |
4 ms |
5176 KB |
Output is correct |
60 |
Correct |
4 ms |
5204 KB |
Output is correct |
61 |
Correct |
4 ms |
5180 KB |
Output is correct |
62 |
Correct |
4 ms |
5296 KB |
Output is correct |
63 |
Correct |
4 ms |
5332 KB |
Output is correct |
64 |
Correct |
4 ms |
5300 KB |
Output is correct |
65 |
Correct |
4 ms |
5348 KB |
Output is correct |
66 |
Correct |
4 ms |
5176 KB |
Output is correct |
67 |
Correct |
99 ms |
25708 KB |
Output is correct |
68 |
Correct |
137 ms |
36300 KB |
Output is correct |
69 |
Correct |
127 ms |
27932 KB |
Output is correct |
70 |
Correct |
121 ms |
28844 KB |
Output is correct |
71 |
Correct |
126 ms |
28796 KB |
Output is correct |
72 |
Correct |
156 ms |
33180 KB |
Output is correct |
73 |
Correct |
119 ms |
31792 KB |
Output is correct |
74 |
Correct |
86 ms |
23136 KB |
Output is correct |
75 |
Correct |
100 ms |
25080 KB |
Output is correct |
76 |
Correct |
123 ms |
27888 KB |
Output is correct |
77 |
Correct |
156 ms |
38708 KB |
Output is correct |
78 |
Correct |
139 ms |
37376 KB |
Output is correct |
79 |
Correct |
104 ms |
25208 KB |
Output is correct |
80 |
Correct |
81 ms |
24944 KB |
Output is correct |
81 |
Correct |
141 ms |
30260 KB |
Output is correct |
82 |
Correct |
138 ms |
30560 KB |
Output is correct |
83 |
Correct |
170 ms |
38588 KB |
Output is correct |
84 |
Correct |
146 ms |
38372 KB |
Output is correct |
85 |
Correct |
137 ms |
30532 KB |
Output is correct |
86 |
Correct |
99 ms |
25136 KB |
Output is correct |
87 |
Correct |
96 ms |
25140 KB |
Output is correct |
88 |
Correct |
114 ms |
30588 KB |
Output is correct |
89 |
Correct |
122 ms |
32596 KB |
Output is correct |
90 |
Correct |
125 ms |
26308 KB |
Output is correct |
91 |
Correct |
124 ms |
27284 KB |
Output is correct |
92 |
Correct |
135 ms |
28984 KB |
Output is correct |
93 |
Correct |
140 ms |
31584 KB |
Output is correct |
94 |
Correct |
152 ms |
28112 KB |
Output is correct |
95 |
Correct |
97 ms |
25152 KB |
Output is correct |
96 |
Correct |
89 ms |
28844 KB |
Output is correct |
97 |
Correct |
74 ms |
18352 KB |
Output is correct |
98 |
Correct |
144 ms |
32928 KB |
Output is correct |
99 |
Correct |
131 ms |
32092 KB |
Output is correct |
100 |
Correct |
51 ms |
10780 KB |
Output is correct |
101 |
Correct |
142 ms |
27452 KB |
Output is correct |
102 |
Correct |
123 ms |
24580 KB |
Output is correct |
103 |
Correct |
118 ms |
22660 KB |
Output is correct |
104 |
Correct |
129 ms |
25464 KB |
Output is correct |