#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int nx=2e5+5;
int n, m, sz[2*nx], u, v, dsu[2*nx], cnt;
vector<tuple<int, int, int>> d;
vector<pair<int, int>> p;
bool can[2*nx];
int find(int x)
{
if (dsu[x]==x) return x;
return dsu[x]=find(dsu[x]);
}
void dfs(int u)
{
if (u<=n) return;
if (!can[u]) can[p[u].first]=can[p[u].second]=0;
dfs(p[u].first); dfs(p[u].second);
}
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>n>>m;
for (int i=1; i<=2*n; i++) can[i]=1, dsu[i]=i;
for (int i=1; i<=n; i++) cin>>sz[i];
for (int i=0; i<m; i++) cin>>u>>v, d.push_back({max(sz[u], sz[v]), u, v});
sort(d.begin(), d.end());
p.resize(n+1); cnt=n;
for (int i=0; i<m; i++)
{
auto [w, u, v]=d[i];
int pu=find(u), pv=find(v);
if (pu==pv) continue;
if (sz[pu]<w) can[pu]=0;
if (sz[pv]<w) can[pv]=0;
dsu[pu]=dsu[pv]=++cnt;
sz[cnt]=sz[pu]+sz[pv];
p.push_back({pu, pv});
}
dfs(cnt);
for (int i=2; i<=n; i++)
{
if (find(i)!=find(1))
{
cout<<string(n, '0');
return 0;
}
}
for (int i=1; i<=n; i++) cout<<can[i]?'1':'0';
}
Compilation message
island.cpp: In function 'int main()':
island.cpp:55:50: warning: second operand of conditional expression has no effect [-Wunused-value]
55 | for (int i=1; i<=n; i++) cout<<can[i]?'1':'0';
| ^
island.cpp:55:50: warning: third operand of conditional expression has no effect [-Wunused-value]
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2648 KB |
Output is correct |
4 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Incorrect |
75 ms |
11016 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2392 KB |
Output is correct |
2 |
Incorrect |
79 ms |
9612 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Incorrect |
87 ms |
10204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
1 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2648 KB |
Output is correct |
4 |
Incorrect |
1 ms |
2396 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |