#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
int n,m;
vector<priority_queue<ii,vector<ii>, greater<ii>>>adj;
priority_queue<ii,vector<ii>, greater<ii>> q;
vector<int> v,poder;
vector<set<int>> ok;
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m;
v.assign(n+2,0); adj.resize(n+2);
poder.assign(n+2,0);
ok.resize(n+2);
for(int i=1; i<=n; i++){
int a; cin >> a; v[i] = a;
poder[i] = a;
ok[i].insert(i);// saber quem tá no grupo de quem no final // lista valida
q.push({a, i});// valor indice
}
for(int i=0; i<m; i++){
int a, b; cin >> a >> b;
adj[a].push({v[b], b});
adj[b].push({v[a], a});
}
vector<int> vis(n+2,0);
int ant = 0;
while(!q.empty()){
auto [a,b] = q.top(); q.pop();
if(vis[b] == 1) continue;
if(poder[b] != a) continue;
vis[b] = 1;ant = b;
bool blz = 1;
while(!adj[b].empty() and blz){
auto [aa, bb] = adj[b].top(); adj[b].pop();
if(vis[bb]) continue;
blz = 0;
if(poder[b] >= aa){ // add na resposta (b compartilha a mesma resposta bb)
if(ok[b].size() > ok[bb].size()) swap(ok[b], ok[bb]);
for(auto i: ok[b]) ok[bb].insert(i);
}
poder[bb] += a;
q.push({poder[bb], bb});
if(adj[b].size() > adj[bb].size()) swap(adj[b], adj[bb]);
while(!adj[b].empty()){ //small to large para redirecionar as arestas
adj[bb].push(adj[b].top());
adj[b].pop();
}
}
}
vector<int> res(n+2);
for(auto i: ok[ant]){
res[i] = 1;
}
for(int i = 1; i<=n; i++) cout << res[i];
cout << endl;
}
Compilation message
island.cpp: In function 'int main()':
island.cpp:44:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
44 | auto [a,b] = q.top(); q.pop();
| ^
island.cpp:52:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
52 | auto [aa, bb] = adj[b].top(); adj[b].pop();
| ^
# |
결과 |
실행 시간 |
메모리 |
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 |
Incorrect |
2 ms |
860 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
214 ms |
53476 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
235 ms |
52156 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
262 ms |
52860 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
Incorrect |
2 ms |
860 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |