#include <iostream>
#include <bits/stdc++.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <deque>
#include <set>
#include <stack>
#include <string>
#include <map>
#include <queue>
#define int long long
#define sqrt sqrtl
using namespace std;
const long long oo = 1000000000000000000;
long long sum, ans = 0, mx = 0, mn = 1000000000, num, pos;
/*
ViHHiPuh
(( `'-""``""-'` ))
)-__-_.._-__-(
/ --- (o _ o) --- \
\ .-* ( .0. ) *-. /
_'-. ,_ '=' _, .-'_
/ `;#'#'# - #'#'#;` \
\_)) -----'#'----- ((_/
# --------- #
'# ------- ------ #'
/..-'# ------- #'-.\
_\...-\'# -- #'/-.../_
((____)- '#' -(____))
cout << fixed << setprecision(6) << x;
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
freopen ( "sum.in", "r", stdin )
*/
int n, m, a[ 200001 ], x, y, p[ 200001 ], r[ 200001 ], c[ 200001 ];
int an[ 200001 ];
vector <int> v[ 200001 ], v1;
vector <pair<int, pair<int, int> > > vv;
map <int, vector <int> > mp;
set <int> s[ 200001 ];
set <int> st, stt;
int used[ 200001 ];
int fin( int a ) {
if ( p[ a ] == a )
return a;
return p[ a ] = fin( p[ a ] );
}
void unin( int a, int b ) {
a = fin( a );
b = fin( b );
if ( a == b )
return;
if ( r[ a ] < r[ b ] )
swap( a, b );
r[ a] += r[ b ];
for ( auto i : s[ b ] )
s[ a ].insert( i );
c[ a ] += c[ b ];
p[ b ] = a;
}
void dfs( int u ) {
an[ u ] = 0;
used[ u ] = 1;
for ( auto to : v[ u ] ) {
if ( !used[ to ] )
dfs( to );
}
}
main () {
cin >> n >> m;
for ( int i = 1; i <= n; i ++ ) {
cin >> a[ i ];
an[ i ] = 1;
p[ i ] = i;
r[ i ] = 1;
c[ i ] = a[ i ];
mp[ a[ i ] ].push_back( i );
st.insert( a[ i ] );
}
for ( int i = 1; i <= m; i ++ ) {
cin >> x >> y;
if ( a[ x ] < a[ y ] )
swap( x, y );
vv.push_back( { a[ x ], make_pair( x, y ) } );
}
sort( vv.begin(), vv.end() );
reverse( vv.begin(), vv.end() );
stt = st;
for ( auto i : st ) {
if ( stt.size() )
stt.erase( stt.begin() );
if ( stt.size() )
ans = *stt.begin();
else
ans = 0;
while ( vv.size() && vv.back().first <= i ) {
num = fin( vv.back().second.second );
if ( c[ num ] < vv.back().first ) {
dfs( vv.back().second.second );
for ( int j = 1; j <= n; j ++ )
used[ j ] = 0;
}
v[ vv.back().second.first ].push_back( vv.back().second.second );
v[ vv.back().second.second ].push_back( vv.back().second.first );
unin( vv.back().second.first, vv.back().second.second );
vv.pop_back();
}
}
for ( int i = 1; i <= n; i ++ )
cout << an[ i ];
}
Compilation message
island.cpp:85:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
85 | main () {
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
14420 KB |
Output is correct |
2 |
Correct |
8 ms |
14420 KB |
Output is correct |
3 |
Correct |
7 ms |
14344 KB |
Output is correct |
4 |
Correct |
11 ms |
14932 KB |
Output is correct |
5 |
Correct |
12 ms |
14932 KB |
Output is correct |
6 |
Correct |
10 ms |
14676 KB |
Output is correct |
7 |
Correct |
10 ms |
14804 KB |
Output is correct |
8 |
Correct |
11 ms |
14804 KB |
Output is correct |
9 |
Correct |
9 ms |
14676 KB |
Output is correct |
10 |
Correct |
11 ms |
14932 KB |
Output is correct |
11 |
Correct |
12 ms |
14932 KB |
Output is correct |
12 |
Correct |
11 ms |
14864 KB |
Output is correct |
13 |
Correct |
9 ms |
14708 KB |
Output is correct |
14 |
Correct |
10 ms |
14676 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
14420 KB |
Output is correct |
2 |
Correct |
7 ms |
14420 KB |
Output is correct |
3 |
Execution timed out |
1081 ms |
69388 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
14420 KB |
Output is correct |
2 |
Execution timed out |
1078 ms |
68880 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
14420 KB |
Output is correct |
2 |
Execution timed out |
1068 ms |
31600 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
14420 KB |
Output is correct |
2 |
Correct |
8 ms |
14420 KB |
Output is correct |
3 |
Correct |
7 ms |
14344 KB |
Output is correct |
4 |
Correct |
11 ms |
14932 KB |
Output is correct |
5 |
Correct |
12 ms |
14932 KB |
Output is correct |
6 |
Correct |
10 ms |
14676 KB |
Output is correct |
7 |
Correct |
10 ms |
14804 KB |
Output is correct |
8 |
Correct |
11 ms |
14804 KB |
Output is correct |
9 |
Correct |
9 ms |
14676 KB |
Output is correct |
10 |
Correct |
11 ms |
14932 KB |
Output is correct |
11 |
Correct |
12 ms |
14932 KB |
Output is correct |
12 |
Correct |
11 ms |
14864 KB |
Output is correct |
13 |
Correct |
9 ms |
14708 KB |
Output is correct |
14 |
Correct |
10 ms |
14676 KB |
Output is correct |
15 |
Correct |
7 ms |
14420 KB |
Output is correct |
16 |
Correct |
7 ms |
14420 KB |
Output is correct |
17 |
Execution timed out |
1081 ms |
69388 KB |
Time limit exceeded |
18 |
Halted |
0 ms |
0 KB |
- |