#include<bits/stdc++.h>
using namespace std;
vector<int> haha[200001];
int main()
{
ios_base::sync_with_stdio(NULL);
cin.tie(NULL);
cout.tie(NULL);
int n,m,a,b;
cin >> n >> m;
vector<int> wow(n+1);
vector<pair<int,int>> wut(0);
for(int i = 1; i <= n; i++) {
cin >> wow[i];
wut.push_back({wow[i],i});
}
sort(wut.begin(),wut.end());
for(int i = 0; i < m; i++) {
cin >> a >> b;
haha[a].push_back(b);
haha[b].push_back(a);
}
vector<int> ans(n+1);
vector<bool> bruh(n+1,true);
vector<int> no(n+1,-1);
for(int i = 1; i <= n; i++) {
if(bruh[i] == false) {
continue;
}
priority_queue<pair<int,int>> idk;
long long sb = 0;
idk.push({-wow[i],i});
vector<int> yeah(0);
while(!idk.empty()) {
a = -idk.top().first;
b = idk.top().second;
idk.pop();
if(no[b] == i) {
continue;
}
if(wow[b] > sb && b != i) {
break;
}
if(ans[b]) {
ans[i] = 1;
break;
}
sb+=wow[b];
yeah.push_back(b);
no[b] = i;
for(int v: haha[b]) {
if(no[v] != i) {
idk.push({-wow[v],v});
}
}
}
if(yeah.size() == n) {
ans[i] = 1;
}
if(ans[i] == 0) {
for(int j = 0; j < yeah.size(); j++) {
bruh[yeah[j]] = 0;
}
}
}
for(int i = 1; i <= n; i++) {
cout << ans[i];
}
cout << endl;
return 0;
}
Compilation message
island.cpp: In function 'int main()':
island.cpp:59:24: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
59 | if(yeah.size() == n) {
| ~~~~~~~~~~~~^~~~
island.cpp:63:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
63 | for(int j = 0; j < yeah.size(); j++) {
| ~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
5092 KB |
Output is correct |
2 |
Correct |
2 ms |
4956 KB |
Output is correct |
3 |
Correct |
2 ms |
4956 KB |
Output is correct |
4 |
Correct |
4 ms |
5212 KB |
Output is correct |
5 |
Correct |
4 ms |
5212 KB |
Output is correct |
6 |
Correct |
80 ms |
5256 KB |
Output is correct |
7 |
Correct |
5 ms |
5212 KB |
Output is correct |
8 |
Correct |
4 ms |
5048 KB |
Output is correct |
9 |
Correct |
3 ms |
5212 KB |
Output is correct |
10 |
Correct |
3 ms |
5236 KB |
Output is correct |
11 |
Correct |
4 ms |
5208 KB |
Output is correct |
12 |
Correct |
3 ms |
5212 KB |
Output is correct |
13 |
Correct |
2 ms |
5172 KB |
Output is correct |
14 |
Correct |
11 ms |
5208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
4952 KB |
Output is correct |
2 |
Correct |
2 ms |
4956 KB |
Output is correct |
3 |
Execution timed out |
1096 ms |
21680 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
2 |
Correct |
186 ms |
21448 KB |
Output is correct |
3 |
Correct |
200 ms |
21452 KB |
Output is correct |
4 |
Execution timed out |
1027 ms |
21660 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4952 KB |
Output is correct |
2 |
Correct |
413 ms |
21416 KB |
Output is correct |
3 |
Correct |
571 ms |
21540 KB |
Output is correct |
4 |
Correct |
497 ms |
21680 KB |
Output is correct |
5 |
Execution timed out |
1081 ms |
21632 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
5092 KB |
Output is correct |
2 |
Correct |
2 ms |
4956 KB |
Output is correct |
3 |
Correct |
2 ms |
4956 KB |
Output is correct |
4 |
Correct |
4 ms |
5212 KB |
Output is correct |
5 |
Correct |
4 ms |
5212 KB |
Output is correct |
6 |
Correct |
80 ms |
5256 KB |
Output is correct |
7 |
Correct |
5 ms |
5212 KB |
Output is correct |
8 |
Correct |
4 ms |
5048 KB |
Output is correct |
9 |
Correct |
3 ms |
5212 KB |
Output is correct |
10 |
Correct |
3 ms |
5236 KB |
Output is correct |
11 |
Correct |
4 ms |
5208 KB |
Output is correct |
12 |
Correct |
3 ms |
5212 KB |
Output is correct |
13 |
Correct |
2 ms |
5172 KB |
Output is correct |
14 |
Correct |
11 ms |
5208 KB |
Output is correct |
15 |
Correct |
3 ms |
4952 KB |
Output is correct |
16 |
Correct |
2 ms |
4956 KB |
Output is correct |
17 |
Execution timed out |
1096 ms |
21680 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |