#include <bits/stdc++.h>
using namespace std;
#define int long long
pair<int,int> s[200010];
int v[200010];
vector<int> e[200010];
int vis[200010],ans[200010];
struct comp{
int val,num;
bool operator < (const comp &cmp) const{
return val>cmp.val;
}
};
signed main(){
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int n,m;cin>>n>>m;
for (int i=1;i<=n;i++){
cin>>s[i].first;s[i].second=i;
v[i]=s[i].first;
ans[i]=-1;
}
sort(s+1,s+n+1);
for (int i=1;i<=m;i++){
int a,b;cin>>a>>b;
e[a].push_back(b);e[b].push_back(a);
}
for (int i=1;i<=n;i++){
if (ans[s[i].second]>=0) continue;
priority_queue<comp> pq;
int sum=0,mx=0;
pq.push({s[i].first,s[i].second});
vector<int> as;
int got=1;
vis[s[i].second]=i;
while (pq.size()){
auto k=pq.top();pq.pop();
if (k.val>sum && sum>0){
got=0;break;
}
if (k.val>=mx){
if (ans[k.num]!=-1){
got=ans[k.num];break;
}
mx=k.val;as.push_back(k.num);
}
sum+=k.val;
for (auto x:e[k.num]){
if (vis[x]==i) continue;
vis[x]=i;
pq.push({v[x],x});
}
}
for (auto x:as) ans[x]=got;
}
for (int i=1;i<=n;i++) cout<<ans[i];
cout<<"\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4956 KB |
Output is correct |
2 |
Correct |
2 ms |
4956 KB |
Output is correct |
3 |
Correct |
2 ms |
4956 KB |
Output is correct |
4 |
Correct |
3 ms |
5212 KB |
Output is correct |
5 |
Correct |
4 ms |
5340 KB |
Output is correct |
6 |
Correct |
3 ms |
5212 KB |
Output is correct |
7 |
Correct |
4 ms |
5212 KB |
Output is correct |
8 |
Correct |
3 ms |
5212 KB |
Output is correct |
9 |
Correct |
3 ms |
5184 KB |
Output is correct |
10 |
Correct |
3 ms |
5212 KB |
Output is correct |
11 |
Correct |
3 ms |
5364 KB |
Output is correct |
12 |
Correct |
4 ms |
5212 KB |
Output is correct |
13 |
Correct |
3 ms |
5212 KB |
Output is correct |
14 |
Correct |
3 ms |
5212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
2 ms |
5160 KB |
Output is correct |
3 |
Correct |
93 ms |
25408 KB |
Output is correct |
4 |
Correct |
82 ms |
24900 KB |
Output is correct |
5 |
Correct |
198 ms |
23992 KB |
Output is correct |
6 |
Correct |
186 ms |
24792 KB |
Output is correct |
7 |
Correct |
191 ms |
24672 KB |
Output is correct |
8 |
Correct |
92 ms |
26832 KB |
Output is correct |
9 |
Correct |
179 ms |
25948 KB |
Output is correct |
10 |
Correct |
104 ms |
28632 KB |
Output is correct |
11 |
Correct |
95 ms |
30776 KB |
Output is correct |
12 |
Correct |
99 ms |
23636 KB |
Output is correct |
13 |
Correct |
83 ms |
23748 KB |
Output is correct |
14 |
Correct |
84 ms |
23748 KB |
Output is correct |
15 |
Correct |
87 ms |
25284 KB |
Output is correct |
16 |
Correct |
66 ms |
24520 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4952 KB |
Output is correct |
2 |
Correct |
192 ms |
23640 KB |
Output is correct |
3 |
Correct |
184 ms |
23676 KB |
Output is correct |
4 |
Correct |
92 ms |
25288 KB |
Output is correct |
5 |
Correct |
78 ms |
23756 KB |
Output is correct |
6 |
Correct |
194 ms |
23632 KB |
Output is correct |
7 |
Correct |
87 ms |
25284 KB |
Output is correct |
8 |
Correct |
105 ms |
25284 KB |
Output is correct |
9 |
Correct |
66 ms |
24520 KB |
Output is correct |
10 |
Correct |
89 ms |
24012 KB |
Output is correct |
11 |
Correct |
140 ms |
22660 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
192 ms |
25208 KB |
Output is correct |
3 |
Correct |
161 ms |
25008 KB |
Output is correct |
4 |
Correct |
157 ms |
25036 KB |
Output is correct |
5 |
Correct |
109 ms |
26860 KB |
Output is correct |
6 |
Correct |
93 ms |
26312 KB |
Output is correct |
7 |
Correct |
85 ms |
31804 KB |
Output is correct |
8 |
Correct |
85 ms |
27548 KB |
Output is correct |
9 |
Correct |
93 ms |
18080 KB |
Output is correct |
10 |
Correct |
114 ms |
25384 KB |
Output is correct |
11 |
Correct |
121 ms |
22700 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4956 KB |
Output is correct |
2 |
Correct |
2 ms |
4956 KB |
Output is correct |
3 |
Correct |
2 ms |
4956 KB |
Output is correct |
4 |
Correct |
3 ms |
5212 KB |
Output is correct |
5 |
Correct |
4 ms |
5340 KB |
Output is correct |
6 |
Correct |
3 ms |
5212 KB |
Output is correct |
7 |
Correct |
4 ms |
5212 KB |
Output is correct |
8 |
Correct |
3 ms |
5212 KB |
Output is correct |
9 |
Correct |
3 ms |
5184 KB |
Output is correct |
10 |
Correct |
3 ms |
5212 KB |
Output is correct |
11 |
Correct |
3 ms |
5364 KB |
Output is correct |
12 |
Correct |
4 ms |
5212 KB |
Output is correct |
13 |
Correct |
3 ms |
5212 KB |
Output is correct |
14 |
Correct |
3 ms |
5212 KB |
Output is correct |
15 |
Correct |
2 ms |
4956 KB |
Output is correct |
16 |
Correct |
2 ms |
5160 KB |
Output is correct |
17 |
Correct |
93 ms |
25408 KB |
Output is correct |
18 |
Correct |
82 ms |
24900 KB |
Output is correct |
19 |
Correct |
198 ms |
23992 KB |
Output is correct |
20 |
Correct |
186 ms |
24792 KB |
Output is correct |
21 |
Correct |
191 ms |
24672 KB |
Output is correct |
22 |
Correct |
92 ms |
26832 KB |
Output is correct |
23 |
Correct |
179 ms |
25948 KB |
Output is correct |
24 |
Correct |
104 ms |
28632 KB |
Output is correct |
25 |
Correct |
95 ms |
30776 KB |
Output is correct |
26 |
Correct |
99 ms |
23636 KB |
Output is correct |
27 |
Correct |
83 ms |
23748 KB |
Output is correct |
28 |
Correct |
84 ms |
23748 KB |
Output is correct |
29 |
Correct |
87 ms |
25284 KB |
Output is correct |
30 |
Correct |
66 ms |
24520 KB |
Output is correct |
31 |
Correct |
3 ms |
4952 KB |
Output is correct |
32 |
Correct |
192 ms |
23640 KB |
Output is correct |
33 |
Correct |
184 ms |
23676 KB |
Output is correct |
34 |
Correct |
92 ms |
25288 KB |
Output is correct |
35 |
Correct |
78 ms |
23756 KB |
Output is correct |
36 |
Correct |
194 ms |
23632 KB |
Output is correct |
37 |
Correct |
87 ms |
25284 KB |
Output is correct |
38 |
Correct |
105 ms |
25284 KB |
Output is correct |
39 |
Correct |
66 ms |
24520 KB |
Output is correct |
40 |
Correct |
89 ms |
24012 KB |
Output is correct |
41 |
Correct |
140 ms |
22660 KB |
Output is correct |
42 |
Correct |
2 ms |
4956 KB |
Output is correct |
43 |
Correct |
192 ms |
25208 KB |
Output is correct |
44 |
Correct |
161 ms |
25008 KB |
Output is correct |
45 |
Correct |
157 ms |
25036 KB |
Output is correct |
46 |
Correct |
109 ms |
26860 KB |
Output is correct |
47 |
Correct |
93 ms |
26312 KB |
Output is correct |
48 |
Correct |
85 ms |
31804 KB |
Output is correct |
49 |
Correct |
85 ms |
27548 KB |
Output is correct |
50 |
Correct |
93 ms |
18080 KB |
Output is correct |
51 |
Correct |
114 ms |
25384 KB |
Output is correct |
52 |
Correct |
121 ms |
22700 KB |
Output is correct |
53 |
Correct |
2 ms |
4956 KB |
Output is correct |
54 |
Correct |
2 ms |
4956 KB |
Output is correct |
55 |
Correct |
2 ms |
4956 KB |
Output is correct |
56 |
Correct |
3 ms |
5212 KB |
Output is correct |
57 |
Correct |
4 ms |
5212 KB |
Output is correct |
58 |
Correct |
3 ms |
5228 KB |
Output is correct |
59 |
Correct |
3 ms |
5212 KB |
Output is correct |
60 |
Correct |
3 ms |
5212 KB |
Output is correct |
61 |
Correct |
3 ms |
5284 KB |
Output is correct |
62 |
Correct |
3 ms |
5236 KB |
Output is correct |
63 |
Correct |
4 ms |
5212 KB |
Output is correct |
64 |
Correct |
4 ms |
5468 KB |
Output is correct |
65 |
Correct |
3 ms |
5212 KB |
Output is correct |
66 |
Correct |
4 ms |
5212 KB |
Output is correct |
67 |
Correct |
96 ms |
25548 KB |
Output is correct |
68 |
Correct |
82 ms |
24880 KB |
Output is correct |
69 |
Correct |
181 ms |
24092 KB |
Output is correct |
70 |
Correct |
184 ms |
24656 KB |
Output is correct |
71 |
Correct |
173 ms |
24660 KB |
Output is correct |
72 |
Correct |
107 ms |
26832 KB |
Output is correct |
73 |
Correct |
149 ms |
25936 KB |
Output is correct |
74 |
Correct |
121 ms |
28624 KB |
Output is correct |
75 |
Correct |
96 ms |
30780 KB |
Output is correct |
76 |
Correct |
103 ms |
23540 KB |
Output is correct |
77 |
Correct |
83 ms |
23748 KB |
Output is correct |
78 |
Correct |
96 ms |
23784 KB |
Output is correct |
79 |
Correct |
83 ms |
25288 KB |
Output is correct |
80 |
Correct |
64 ms |
24520 KB |
Output is correct |
81 |
Correct |
202 ms |
23756 KB |
Output is correct |
82 |
Correct |
193 ms |
23636 KB |
Output is correct |
83 |
Correct |
98 ms |
25216 KB |
Output is correct |
84 |
Correct |
87 ms |
23656 KB |
Output is correct |
85 |
Correct |
195 ms |
23820 KB |
Output is correct |
86 |
Correct |
91 ms |
25280 KB |
Output is correct |
87 |
Correct |
102 ms |
25240 KB |
Output is correct |
88 |
Correct |
95 ms |
24012 KB |
Output is correct |
89 |
Correct |
147 ms |
22732 KB |
Output is correct |
90 |
Correct |
177 ms |
25036 KB |
Output is correct |
91 |
Correct |
155 ms |
24916 KB |
Output is correct |
92 |
Correct |
164 ms |
24916 KB |
Output is correct |
93 |
Correct |
120 ms |
26696 KB |
Output is correct |
94 |
Correct |
104 ms |
26428 KB |
Output is correct |
95 |
Correct |
98 ms |
31796 KB |
Output is correct |
96 |
Correct |
84 ms |
27484 KB |
Output is correct |
97 |
Correct |
100 ms |
18084 KB |
Output is correct |
98 |
Correct |
110 ms |
25300 KB |
Output is correct |
99 |
Correct |
120 ms |
22736 KB |
Output is correct |
100 |
Correct |
28 ms |
11612 KB |
Output is correct |
101 |
Correct |
247 ms |
24752 KB |
Output is correct |
102 |
Correct |
101 ms |
24860 KB |
Output is correct |
103 |
Correct |
150 ms |
24020 KB |
Output is correct |
104 |
Correct |
193 ms |
24868 KB |
Output is correct |