#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) {
a=find(a,dsu);
b=find(b,dsu);
dsu[b]=a;
ev[a]+=ev[b];
}
int main()
{
long long n,m;
cin>>n>>m;
vector<long long> v(n),ev(n),dsu(n);
vector<pair<long long,long long>> s;
for (long long i = 0; i < n; ++i) {
long long 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);
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);
g[x].push_back(y);
g[y].push_back(x);
ed.push_back({{v[x],v[y]},{x,y}});
}
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 (int j = 0; j < g[i].size()-1; ++j) {
if(v[g[i][j]]>=v[i])ed.push_back({{v[g[i][j]],v[g[i][j+1]]},{g[i][j],g[i][j+1]}});
}
}
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);
}
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:42:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
42 | for (int j = 0; j < g[i].size()-1; ++j) {
| ~~^~~~~~~~~~~~~~~
island.cpp:47:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
47 | for (auto [u,t]:ed) {
| ^
island.cpp:48:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
48 | auto [a,b] = t;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Runtime error |
0 ms |
348 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Runtime error |
0 ms |
348 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
0 ms |
348 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
2 |
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 |
Runtime error |
0 ms |
348 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |