#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
#define pb push_back
#define pp pop_back
#define ff first
#define ss second
#define lb lower_bound
typedef tree<int, null_type, less<int>, rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
int N, M, S[200001];
vector<int> adj[200001];
void subtask2() {
string res(N, '0');
for(int l = 1; l <= N; l++) {
if(S[l] != S[1]) continue;
res[l - 1] = '1';
}
cout << res << "\n";
}
int32_t main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> N >> M; int R = 0; string res(N, '0');
for(int l = 1; l <= N; l++)
cin >> S[l], R += S[l];
for(int l = 0; l < M; l++) {
int U, V; cin >> U >> V;
adj[U].pb(V); adj[V].pb(U);
}
bool ok = (adj[1].size() == N - 1);
for(int l = 2; l <= N; l++) {
ok &= (adj[l].size() == 1);
int U = adj[l][0];
ok &= (U < l); ok &= (S[l] <= S[l - 1]);
}
if(ok) {
subtask2();
return 0;
}
for(int l = 1; l <= N; l++) {
int curr = 0;
priority_queue<ii, vector<ii>, greater<ii>> pq;
pq.push({0, l}); vector<bool> vis(N + 1, 0);
while(!pq.empty()) {
int A = pq.top().second, B = pq.top().first; pq.pop();
if(vis[A] || (S[A] > curr && A != l)) continue;
vis[A] = 1; curr += S[A];
for(auto E : adj[A]) {
if(vis[E]) continue;
pq.push({S[E], E});
}
}
if(curr == R) res[l - 1] = '1';
}
cout << res << "\n";
}
Compilation message
island.cpp: In function 'int32_t main()':
island.cpp:40:38: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
40 | bool ok = (adj[1].size() == N - 1);
| ~~~~~~~~~~~~~~^~~~~~~~
island.cpp:55:46: warning: unused variable 'B' [-Wunused-variable]
55 | int A = pq.top().second, B = pq.top().first; pq.pop();
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Incorrect |
4 ms |
5076 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Incorrect |
379 ms |
12420 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Incorrect |
267 ms |
12364 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Incorrect |
337 ms |
12492 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
3 ms |
4948 KB |
Output is correct |
4 |
Incorrect |
4 ms |
5076 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |