#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<int> par;
vector<int> ans;
int cmp(int v){
if (par[v]==v) return v;
return par[v] = cmp(par[v]);
}
void dfs1(vector<int> tree[], ll sum[], ll s[], int v){
sum[v] = s[v];
for (int u : tree[v]){
dfs1(tree,sum,s,u);
sum[v] += sum[u];
}
}
void dfs2(vector<int> tree[], ll sum[], ll s[], int v){
ans[v]=1;
for (int u : tree[v]){
if (sum[u] >= s[v]){
dfs2(tree,sum,s,u);
}
}
}
int main(){
ios_base::sync_with_stdio(false);cin.tie(NULL);
int n,m;
cin >> n >> m;
ll s[n];
for (int i=0;i<n;i++){
cin >> s[i];
}
vector<int> nei[n],tree[n];
for (int i=0;i<m;i++){
int a,b;
cin>>a>>b;
a--;b--;
nei[a].push_back(b);
nei[b].push_back(a);
}
par.resize(n);
iota(par.begin(),par.end(),0);
vector<int> ord(n);
iota(ord.begin(),ord.end(),0);
sort(ord.begin(),ord.end(),[&](int l, int r){return s[l] < s[r];});
bool vis[n]={0};
for (int v : ord){
vis[v]=1;
for (int u : nei[v]){
if (vis[u]){
u = cmp(u);
if (u==v)continue;
tree[v].push_back(u);
par[u] = v;
}
}
}
ans.resize(n);
ll sum[n];
dfs1(tree,sum,s,ord.back());
dfs2(tree,sum,s,ord.back());
for (int i=0;i<n;i++){
cout<<ans[i];
}
cout<<"\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
716 KB |
Output is correct |
10 |
Correct |
1 ms |
768 KB |
Output is correct |
11 |
Correct |
2 ms |
600 KB |
Output is correct |
12 |
Correct |
1 ms |
604 KB |
Output is correct |
13 |
Correct |
1 ms |
644 KB |
Output is correct |
14 |
Correct |
2 ms |
604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
372 KB |
Output is correct |
3 |
Correct |
93 ms |
36832 KB |
Output is correct |
4 |
Correct |
92 ms |
30544 KB |
Output is correct |
5 |
Correct |
104 ms |
29268 KB |
Output is correct |
6 |
Correct |
111 ms |
30308 KB |
Output is correct |
7 |
Correct |
113 ms |
30292 KB |
Output is correct |
8 |
Correct |
127 ms |
32628 KB |
Output is correct |
9 |
Correct |
90 ms |
29260 KB |
Output is correct |
10 |
Correct |
70 ms |
27204 KB |
Output is correct |
11 |
Correct |
80 ms |
26952 KB |
Output is correct |
12 |
Correct |
99 ms |
29060 KB |
Output is correct |
13 |
Correct |
89 ms |
30804 KB |
Output is correct |
14 |
Correct |
97 ms |
30800 KB |
Output is correct |
15 |
Correct |
105 ms |
48308 KB |
Output is correct |
16 |
Correct |
88 ms |
47164 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
118 ms |
30288 KB |
Output is correct |
3 |
Correct |
130 ms |
30544 KB |
Output is correct |
4 |
Correct |
96 ms |
32176 KB |
Output is correct |
5 |
Correct |
83 ms |
30796 KB |
Output is correct |
6 |
Correct |
130 ms |
30536 KB |
Output is correct |
7 |
Correct |
123 ms |
48148 KB |
Output is correct |
8 |
Correct |
121 ms |
48208 KB |
Output is correct |
9 |
Correct |
81 ms |
46932 KB |
Output is correct |
10 |
Correct |
81 ms |
28872 KB |
Output is correct |
11 |
Correct |
91 ms |
29008 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
138 ms |
31228 KB |
Output is correct |
3 |
Correct |
140 ms |
30548 KB |
Output is correct |
4 |
Correct |
129 ms |
30440 KB |
Output is correct |
5 |
Correct |
139 ms |
30544 KB |
Output is correct |
6 |
Correct |
122 ms |
31032 KB |
Output is correct |
7 |
Correct |
85 ms |
31048 KB |
Output is correct |
8 |
Correct |
92 ms |
39052 KB |
Output is correct |
9 |
Correct |
69 ms |
17716 KB |
Output is correct |
10 |
Correct |
97 ms |
28832 KB |
Output is correct |
11 |
Correct |
92 ms |
29148 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
604 KB |
Output is correct |
9 |
Correct |
1 ms |
716 KB |
Output is correct |
10 |
Correct |
1 ms |
768 KB |
Output is correct |
11 |
Correct |
2 ms |
600 KB |
Output is correct |
12 |
Correct |
1 ms |
604 KB |
Output is correct |
13 |
Correct |
1 ms |
644 KB |
Output is correct |
14 |
Correct |
2 ms |
604 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
372 KB |
Output is correct |
17 |
Correct |
93 ms |
36832 KB |
Output is correct |
18 |
Correct |
92 ms |
30544 KB |
Output is correct |
19 |
Correct |
104 ms |
29268 KB |
Output is correct |
20 |
Correct |
111 ms |
30308 KB |
Output is correct |
21 |
Correct |
113 ms |
30292 KB |
Output is correct |
22 |
Correct |
127 ms |
32628 KB |
Output is correct |
23 |
Correct |
90 ms |
29260 KB |
Output is correct |
24 |
Correct |
70 ms |
27204 KB |
Output is correct |
25 |
Correct |
80 ms |
26952 KB |
Output is correct |
26 |
Correct |
99 ms |
29060 KB |
Output is correct |
27 |
Correct |
89 ms |
30804 KB |
Output is correct |
28 |
Correct |
97 ms |
30800 KB |
Output is correct |
29 |
Correct |
105 ms |
48308 KB |
Output is correct |
30 |
Correct |
88 ms |
47164 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
118 ms |
30288 KB |
Output is correct |
33 |
Correct |
130 ms |
30544 KB |
Output is correct |
34 |
Correct |
96 ms |
32176 KB |
Output is correct |
35 |
Correct |
83 ms |
30796 KB |
Output is correct |
36 |
Correct |
130 ms |
30536 KB |
Output is correct |
37 |
Correct |
123 ms |
48148 KB |
Output is correct |
38 |
Correct |
121 ms |
48208 KB |
Output is correct |
39 |
Correct |
81 ms |
46932 KB |
Output is correct |
40 |
Correct |
81 ms |
28872 KB |
Output is correct |
41 |
Correct |
91 ms |
29008 KB |
Output is correct |
42 |
Correct |
0 ms |
344 KB |
Output is correct |
43 |
Correct |
138 ms |
31228 KB |
Output is correct |
44 |
Correct |
140 ms |
30548 KB |
Output is correct |
45 |
Correct |
129 ms |
30440 KB |
Output is correct |
46 |
Correct |
139 ms |
30544 KB |
Output is correct |
47 |
Correct |
122 ms |
31032 KB |
Output is correct |
48 |
Correct |
85 ms |
31048 KB |
Output is correct |
49 |
Correct |
92 ms |
39052 KB |
Output is correct |
50 |
Correct |
69 ms |
17716 KB |
Output is correct |
51 |
Correct |
97 ms |
28832 KB |
Output is correct |
52 |
Correct |
92 ms |
29148 KB |
Output is correct |
53 |
Correct |
0 ms |
348 KB |
Output is correct |
54 |
Correct |
0 ms |
348 KB |
Output is correct |
55 |
Correct |
0 ms |
348 KB |
Output is correct |
56 |
Correct |
1 ms |
604 KB |
Output is correct |
57 |
Correct |
1 ms |
724 KB |
Output is correct |
58 |
Correct |
1 ms |
572 KB |
Output is correct |
59 |
Correct |
1 ms |
604 KB |
Output is correct |
60 |
Correct |
1 ms |
604 KB |
Output is correct |
61 |
Correct |
1 ms |
860 KB |
Output is correct |
62 |
Correct |
1 ms |
604 KB |
Output is correct |
63 |
Correct |
1 ms |
604 KB |
Output is correct |
64 |
Correct |
1 ms |
728 KB |
Output is correct |
65 |
Correct |
1 ms |
604 KB |
Output is correct |
66 |
Correct |
2 ms |
604 KB |
Output is correct |
67 |
Correct |
110 ms |
36936 KB |
Output is correct |
68 |
Correct |
86 ms |
30548 KB |
Output is correct |
69 |
Correct |
97 ms |
29388 KB |
Output is correct |
70 |
Correct |
106 ms |
30288 KB |
Output is correct |
71 |
Correct |
114 ms |
30284 KB |
Output is correct |
72 |
Correct |
114 ms |
32592 KB |
Output is correct |
73 |
Correct |
91 ms |
29396 KB |
Output is correct |
74 |
Correct |
69 ms |
27008 KB |
Output is correct |
75 |
Correct |
76 ms |
26900 KB |
Output is correct |
76 |
Correct |
111 ms |
28852 KB |
Output is correct |
77 |
Correct |
84 ms |
30804 KB |
Output is correct |
78 |
Correct |
84 ms |
30800 KB |
Output is correct |
79 |
Correct |
106 ms |
48208 KB |
Output is correct |
80 |
Correct |
88 ms |
46932 KB |
Output is correct |
81 |
Correct |
121 ms |
30288 KB |
Output is correct |
82 |
Correct |
127 ms |
30508 KB |
Output is correct |
83 |
Correct |
91 ms |
32340 KB |
Output is correct |
84 |
Correct |
93 ms |
30804 KB |
Output is correct |
85 |
Correct |
117 ms |
30548 KB |
Output is correct |
86 |
Correct |
120 ms |
48212 KB |
Output is correct |
87 |
Correct |
123 ms |
48212 KB |
Output is correct |
88 |
Correct |
94 ms |
28980 KB |
Output is correct |
89 |
Correct |
89 ms |
29012 KB |
Output is correct |
90 |
Correct |
124 ms |
31056 KB |
Output is correct |
91 |
Correct |
130 ms |
30544 KB |
Output is correct |
92 |
Correct |
133 ms |
30352 KB |
Output is correct |
93 |
Correct |
125 ms |
30548 KB |
Output is correct |
94 |
Correct |
116 ms |
31060 KB |
Output is correct |
95 |
Correct |
87 ms |
31152 KB |
Output is correct |
96 |
Correct |
77 ms |
39052 KB |
Output is correct |
97 |
Correct |
78 ms |
17744 KB |
Output is correct |
98 |
Correct |
105 ms |
28832 KB |
Output is correct |
99 |
Correct |
94 ms |
29008 KB |
Output is correct |
100 |
Correct |
27 ms |
5212 KB |
Output is correct |
101 |
Correct |
127 ms |
30628 KB |
Output is correct |
102 |
Correct |
93 ms |
29008 KB |
Output is correct |
103 |
Correct |
142 ms |
30032 KB |
Output is correct |
104 |
Correct |
133 ms |
31572 KB |
Output is correct |