#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int nx=2e5+5;
ll n, m, sz[2*nx], u, v, dsu[2*nx], cnt;
vector<tuple<int, int, int>> d;
vector<pair<int, int>> p;
bool can[2*nx];
int find(int x)
{
if (dsu[x]==x) return x;
return dsu[x]=find(dsu[x]);
}
void dfs(int u)
{
if (u<=n) return;
if (!can[u]) can[p[u].first]=can[p[u].second]=0;
dfs(p[u].first); dfs(p[u].second);
}
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n>>m;
for (int i=1; i<=2*n; i++) can[i]=1, dsu[i]=i;
for (int i=1; i<=n; i++) cin>>sz[i];
for (int i=0; i<m; i++) cin>>u>>v, d.push_back({max(sz[u], sz[v]), u, v});
sort(d.begin(), d.end());
p.resize(n+1); cnt=n;
for (int i=0; i<m; i++)
{
auto [w, u, v]=d[i];
int pu=find(u), pv=find(v);
if (pu==pv) continue;
if (sz[pu]<w) can[pu]=0;
if (sz[pv]<w) can[pv]=0;
dsu[pu]=dsu[pv]=++cnt;
sz[cnt]=sz[pu]+sz[pv];
p.push_back({pu, pv});
}
dfs(cnt);
for (int i=2; i<=n; i++)
{
if (find(i)!=find(1))
{
cout<<string(n, '0');
return 0;
}
}
for (int i=1; i<=n; i++) cout<<(can[i]?'1':'0');
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4636 KB |
Output is correct |
3 |
Correct |
1 ms |
4696 KB |
Output is correct |
4 |
Correct |
2 ms |
4440 KB |
Output is correct |
5 |
Correct |
2 ms |
4440 KB |
Output is correct |
6 |
Correct |
1 ms |
4440 KB |
Output is correct |
7 |
Correct |
1 ms |
4440 KB |
Output is correct |
8 |
Correct |
1 ms |
4440 KB |
Output is correct |
9 |
Correct |
1 ms |
4696 KB |
Output is correct |
10 |
Correct |
2 ms |
4440 KB |
Output is correct |
11 |
Correct |
2 ms |
4444 KB |
Output is correct |
12 |
Correct |
2 ms |
4440 KB |
Output is correct |
13 |
Correct |
1 ms |
4696 KB |
Output is correct |
14 |
Correct |
2 ms |
4440 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4440 KB |
Output is correct |
3 |
Correct |
74 ms |
14256 KB |
Output is correct |
4 |
Correct |
68 ms |
18720 KB |
Output is correct |
5 |
Correct |
73 ms |
18100 KB |
Output is correct |
6 |
Correct |
76 ms |
17316 KB |
Output is correct |
7 |
Correct |
80 ms |
17424 KB |
Output is correct |
8 |
Correct |
91 ms |
20332 KB |
Output is correct |
9 |
Correct |
68 ms |
17448 KB |
Output is correct |
10 |
Correct |
65 ms |
19516 KB |
Output is correct |
11 |
Correct |
69 ms |
19360 KB |
Output is correct |
12 |
Correct |
72 ms |
16540 KB |
Output is correct |
13 |
Correct |
62 ms |
18800 KB |
Output is correct |
14 |
Correct |
66 ms |
18812 KB |
Output is correct |
15 |
Correct |
78 ms |
20752 KB |
Output is correct |
16 |
Correct |
50 ms |
19736 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
77 ms |
13012 KB |
Output is correct |
3 |
Correct |
80 ms |
17456 KB |
Output is correct |
4 |
Correct |
74 ms |
20380 KB |
Output is correct |
5 |
Correct |
62 ms |
18336 KB |
Output is correct |
6 |
Correct |
79 ms |
18624 KB |
Output is correct |
7 |
Correct |
74 ms |
21068 KB |
Output is correct |
8 |
Correct |
72 ms |
20452 KB |
Output is correct |
9 |
Correct |
50 ms |
19640 KB |
Output is correct |
10 |
Correct |
72 ms |
19772 KB |
Output is correct |
11 |
Correct |
71 ms |
17408 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
84 ms |
13540 KB |
Output is correct |
3 |
Correct |
84 ms |
17432 KB |
Output is correct |
4 |
Correct |
84 ms |
18112 KB |
Output is correct |
5 |
Correct |
79 ms |
17572 KB |
Output is correct |
6 |
Correct |
78 ms |
18876 KB |
Output is correct |
7 |
Correct |
69 ms |
20736 KB |
Output is correct |
8 |
Correct |
60 ms |
19876 KB |
Output is correct |
9 |
Correct |
65 ms |
14268 KB |
Output is correct |
10 |
Correct |
78 ms |
15736 KB |
Output is correct |
11 |
Correct |
80 ms |
16796 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4636 KB |
Output is correct |
3 |
Correct |
1 ms |
4696 KB |
Output is correct |
4 |
Correct |
2 ms |
4440 KB |
Output is correct |
5 |
Correct |
2 ms |
4440 KB |
Output is correct |
6 |
Correct |
1 ms |
4440 KB |
Output is correct |
7 |
Correct |
1 ms |
4440 KB |
Output is correct |
8 |
Correct |
1 ms |
4440 KB |
Output is correct |
9 |
Correct |
1 ms |
4696 KB |
Output is correct |
10 |
Correct |
2 ms |
4440 KB |
Output is correct |
11 |
Correct |
2 ms |
4444 KB |
Output is correct |
12 |
Correct |
2 ms |
4440 KB |
Output is correct |
13 |
Correct |
1 ms |
4696 KB |
Output is correct |
14 |
Correct |
2 ms |
4440 KB |
Output is correct |
15 |
Correct |
1 ms |
4440 KB |
Output is correct |
16 |
Correct |
1 ms |
4440 KB |
Output is correct |
17 |
Correct |
74 ms |
14256 KB |
Output is correct |
18 |
Correct |
68 ms |
18720 KB |
Output is correct |
19 |
Correct |
73 ms |
18100 KB |
Output is correct |
20 |
Correct |
76 ms |
17316 KB |
Output is correct |
21 |
Correct |
80 ms |
17424 KB |
Output is correct |
22 |
Correct |
91 ms |
20332 KB |
Output is correct |
23 |
Correct |
68 ms |
17448 KB |
Output is correct |
24 |
Correct |
65 ms |
19516 KB |
Output is correct |
25 |
Correct |
69 ms |
19360 KB |
Output is correct |
26 |
Correct |
72 ms |
16540 KB |
Output is correct |
27 |
Correct |
62 ms |
18800 KB |
Output is correct |
28 |
Correct |
66 ms |
18812 KB |
Output is correct |
29 |
Correct |
78 ms |
20752 KB |
Output is correct |
30 |
Correct |
50 ms |
19736 KB |
Output is correct |
31 |
Correct |
1 ms |
4440 KB |
Output is correct |
32 |
Correct |
77 ms |
13012 KB |
Output is correct |
33 |
Correct |
80 ms |
17456 KB |
Output is correct |
34 |
Correct |
74 ms |
20380 KB |
Output is correct |
35 |
Correct |
62 ms |
18336 KB |
Output is correct |
36 |
Correct |
79 ms |
18624 KB |
Output is correct |
37 |
Correct |
74 ms |
21068 KB |
Output is correct |
38 |
Correct |
72 ms |
20452 KB |
Output is correct |
39 |
Correct |
50 ms |
19640 KB |
Output is correct |
40 |
Correct |
72 ms |
19772 KB |
Output is correct |
41 |
Correct |
71 ms |
17408 KB |
Output is correct |
42 |
Correct |
1 ms |
4440 KB |
Output is correct |
43 |
Correct |
84 ms |
13540 KB |
Output is correct |
44 |
Correct |
84 ms |
17432 KB |
Output is correct |
45 |
Correct |
84 ms |
18112 KB |
Output is correct |
46 |
Correct |
79 ms |
17572 KB |
Output is correct |
47 |
Correct |
78 ms |
18876 KB |
Output is correct |
48 |
Correct |
69 ms |
20736 KB |
Output is correct |
49 |
Correct |
60 ms |
19876 KB |
Output is correct |
50 |
Correct |
65 ms |
14268 KB |
Output is correct |
51 |
Correct |
78 ms |
15736 KB |
Output is correct |
52 |
Correct |
80 ms |
16796 KB |
Output is correct |
53 |
Correct |
1 ms |
4556 KB |
Output is correct |
54 |
Correct |
1 ms |
4440 KB |
Output is correct |
55 |
Correct |
1 ms |
4440 KB |
Output is correct |
56 |
Correct |
2 ms |
4440 KB |
Output is correct |
57 |
Correct |
2 ms |
4612 KB |
Output is correct |
58 |
Correct |
1 ms |
4612 KB |
Output is correct |
59 |
Correct |
2 ms |
4700 KB |
Output is correct |
60 |
Correct |
1 ms |
4444 KB |
Output is correct |
61 |
Correct |
2 ms |
4696 KB |
Output is correct |
62 |
Correct |
1 ms |
4444 KB |
Output is correct |
63 |
Correct |
1 ms |
4612 KB |
Output is correct |
64 |
Correct |
2 ms |
4444 KB |
Output is correct |
65 |
Correct |
1 ms |
4700 KB |
Output is correct |
66 |
Correct |
1 ms |
4444 KB |
Output is correct |
67 |
Correct |
82 ms |
19108 KB |
Output is correct |
68 |
Correct |
73 ms |
18616 KB |
Output is correct |
69 |
Correct |
90 ms |
18336 KB |
Output is correct |
70 |
Correct |
87 ms |
18136 KB |
Output is correct |
71 |
Correct |
89 ms |
17320 KB |
Output is correct |
72 |
Correct |
85 ms |
20320 KB |
Output is correct |
73 |
Correct |
76 ms |
17012 KB |
Output is correct |
74 |
Correct |
73 ms |
20248 KB |
Output is correct |
75 |
Correct |
78 ms |
19252 KB |
Output is correct |
76 |
Correct |
75 ms |
16888 KB |
Output is correct |
77 |
Correct |
94 ms |
19364 KB |
Output is correct |
78 |
Correct |
65 ms |
18720 KB |
Output is correct |
79 |
Correct |
69 ms |
20796 KB |
Output is correct |
80 |
Correct |
50 ms |
19944 KB |
Output is correct |
81 |
Correct |
75 ms |
17244 KB |
Output is correct |
82 |
Correct |
79 ms |
17652 KB |
Output is correct |
83 |
Correct |
70 ms |
20528 KB |
Output is correct |
84 |
Correct |
61 ms |
18080 KB |
Output is correct |
85 |
Correct |
90 ms |
17844 KB |
Output is correct |
86 |
Correct |
71 ms |
21152 KB |
Output is correct |
87 |
Correct |
68 ms |
20384 KB |
Output is correct |
88 |
Correct |
69 ms |
19612 KB |
Output is correct |
89 |
Correct |
68 ms |
17600 KB |
Output is correct |
90 |
Correct |
84 ms |
18076 KB |
Output is correct |
91 |
Correct |
83 ms |
17596 KB |
Output is correct |
92 |
Correct |
87 ms |
17852 KB |
Output is correct |
93 |
Correct |
81 ms |
17572 KB |
Output is correct |
94 |
Correct |
79 ms |
19136 KB |
Output is correct |
95 |
Correct |
70 ms |
20380 KB |
Output is correct |
96 |
Correct |
59 ms |
19188 KB |
Output is correct |
97 |
Correct |
64 ms |
14264 KB |
Output is correct |
98 |
Correct |
72 ms |
16212 KB |
Output is correct |
99 |
Correct |
69 ms |
17036 KB |
Output is correct |
100 |
Correct |
47 ms |
9012 KB |
Output is correct |
101 |
Correct |
88 ms |
17336 KB |
Output is correct |
102 |
Correct |
78 ms |
17656 KB |
Output is correct |
103 |
Correct |
84 ms |
18632 KB |
Output is correct |
104 |
Correct |
82 ms |
18872 KB |
Output is correct |