#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
long long find(long long p, vector<long long> &dsu) {
if(p==dsu[p]) return p;
long long u = find(dsu[p],dsu);
dsu[p]=u;
return u;
}
void un(long long a,long long b,vector<long long> &dsu,vector<long long> &ev,vector<long long> &maxv,vector<vector<long long>> &group) {
a=find(a,dsu);
b=find(b,dsu);
if(maxv[a]>ev[b]) group[b].clear();
if(maxv[b]>ev[a]) group[a].clear();
if(group[a].size()>group[b].size()) swap(a,b);
dsu[a]=b;
maxv[b]=max(maxv[b],maxv[a]);
ev[b]+=ev[a];
}
int main()
{
long long n,m;
cin>>n>>m;
vector<long long> v(n),ev(n),dsu(n),maxv(n);
vector<vector<long long>> group(n);
vector<pair<long long,long long>> s;
for (long long i = 0; i < n; ++i) {
long long x; cin>>x;
ev[i]=x;
maxv[i]=x;
group[i].push_back(x);
v[i]=x;
s.push_back({x,i});
dsu[i]=i;
}
sort(s.begin(), s.end());
vector<pair<pair<long long,long long>,pair<long long,long long>>> ed;
for (long long i = 0; i < m; ++i) {
long long x,y; cin>>x>>y; x--; y--;
if(v[x]>v[y]) swap(x,y);
ed.push_back({{v[x],v[y]},{x,y}});
}
sort(ed.begin(),ed.end());
for (auto [u,t]:ed) {
auto [a,b] = t;
if(ev[find(a,dsu)]>=v[b]) un(a,b,dsu,ev,maxv,group);
}
long long ma = find(s[n-1].second,dsu);
for (long long 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:45:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
45 | for (auto [u,t]:ed) {
| ^
island.cpp:46:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
46 | auto [a,b] = t;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
600 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 |
604 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 |
176 ms |
33040 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
170 ms |
31268 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Incorrect |
192 ms |
31024 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
600 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 |
604 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |