#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;
freopen ( "sum.in", "r", stdin )
*/
int n, m, a[ 400001 ], x, y;
int an[ 200001 ];
int p[ 400001 ], r[ 400001 ], c[ 400001 ];
vector <int> v[ 400001 ];
set <pair<int, int> > st;
int used[ 400001 ];
bool bfs( int u ) {
st.insert( { 0, u } );
used[ u ] = 1;
sum = a[ u ];
while ( st.size() ) {
u = st.begin()->second;
used[ u ] = 1;
int cost = st.begin()->first;
st.erase( st.begin() );
if ( sum < cost )
return false;
sum += cost;
for ( auto to : v[ u ] ) {
if ( !used[ to ] )
st.insert( { a[ to ], to } );
}
}
return true;
}
main () {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> m;
for ( int i = 1; i <= n; i ++ ) {
cin >> a[ i ];
p[ i ] = i;
r[ i ] = 1;
c[ i ] = a[ i ];
st.insert( { a[ i ], i } );
}
for ( int i = 1; i <= m; i ++ ) {
cin >> x >> y;
v[ x ].push_back( y );
v[ y ].push_back( x );
}
for ( int i = 1; i <= n; i ++ ) {
cout << bfs( i );
for ( int j = 1; j <= n; j ++ )
used[ j ] = 0;
}
}
Compilation message
island.cpp:73:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
73 | main () {
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
9684 KB |
Output is correct |
2 |
Correct |
7 ms |
9740 KB |
Output is correct |
3 |
Correct |
9 ms |
9684 KB |
Output is correct |
4 |
Incorrect |
250 ms |
10060 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9684 KB |
Output is correct |
2 |
Correct |
6 ms |
9732 KB |
Output is correct |
3 |
Execution timed out |
1078 ms |
41792 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
9732 KB |
Output is correct |
2 |
Execution timed out |
1059 ms |
40564 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
9732 KB |
Output is correct |
2 |
Execution timed out |
1083 ms |
41592 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
9684 KB |
Output is correct |
2 |
Correct |
7 ms |
9740 KB |
Output is correct |
3 |
Correct |
9 ms |
9684 KB |
Output is correct |
4 |
Incorrect |
250 ms |
10060 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |