#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int find(int p, vector<int> &dsu) {
if(p==dsu[p]) return p;
int u = find(dsu[p],dsu);
dsu[p]=u;
return u;
}
void un(int a,int b,vector<int> &dsu,vector<int> &ev) {
a=find(a,dsu);
b=find(b,dsu);
dsu[b]=a;
ev[a]+=ev[b];
ev[a] = min(1000000000,ev[a]);
}
int main()
{
int n,m;
cin>>n>>m;
vector<int> v(n),ev(n),dsu(n);
vector<pair<int,int>> s;
for (int i = 0; i < n; ++i) {
int x; cin>>x;
ev[i]=x;
v[i]=x;
s.push_back({x,i});
dsu[i]=i;
}
sort(s.begin(), s.end());
vector<vector<int>> g(n);
for (int i = 0; i < m; ++i) {
int x,y; cin>>x>>y; x--; y--;
g[x].push_back(y);
g[y].push_back(x);
}
for (int i = 0; i < n; ++i) {
sort(g[i].begin(),g[i].end(),[v](int a,int b){return v[b]>v[a];});
}
for (auto [val,i]:s) {
for(auto j : g[i]) {
if(ev[find(i,dsu)]>=v[j]&&(v[i]<=v[j])) un(i,j,dsu,ev);
}
}
int ma = find(s[n-1].second,dsu);
for (int i = 0; i < n; ++i) {
if(ma==find(i,dsu))cout<<"1";
else cout<<"0";
}
}
Compilation message
island.cpp: In function 'int main()':
island.cpp:41:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
41 | for (auto [val,i]:s) {
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Incorrect |
3 ms |
604 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
604 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Execution timed out |
1075 ms |
23768 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Execution timed out |
1073 ms |
23184 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Execution timed out |
1084 ms |
23436 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Incorrect |
3 ms |
604 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |