#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 2e5;
bool active[MAX_N + 1], sePoate[MAX_N + 1];
int s[MAX_N + 1];
vector<int> adj[MAX_N + 1];
map<int, vector<int>> updates, queries;
set<int> times;
struct DSU {
int n;
vector<int> sef, sz;
vector<long long> sum;
void init( int _n ) {
n = _n;
sef.resize( n );
sz.resize( n );
sum.resize( n );
for ( int u = 0; u < n; u++ ) {
sef[u] = u;
sz[u] = 1;
sum[u] = s[u];
}
}
int findSef( int v ) {
if ( sef[v] == v )
return v;
sef[v] = findSef( sef[v] );
return sef[v];
}
int calcSz( int v ) {
return sz[findSef( v )];
}
long long calcSum( int v ) {
return sum[findSef( v )];
}
void unionn( int u, int v ) {
u = findSef( u );
v = findSef( v );
if ( sz[u] > sz[v] )
swap( u, v );
if ( u == v )
return;
sef[u] = v;
sz[v] += sz[u];
sum[v] += sum[u];
}
} orase;
int main() {
int n, m;
cin >> n >> m;
for ( int v = 1; v <= n; v++ )
cin >> s[v];
for ( int i = 0; i < m; i++ ) {
int u, v;
cin >> u >> v;
adj[u].push_back( v );
adj[v].push_back( u );
}
for ( int v = 1; v <= n; v++ ) {
updates[s[v]].push_back( v );
queries[s[v]].push_back( v );
times.insert( s[v] );
}
orase.init( n + 1 );
for ( int t: times ) {
for ( int u: updates[t] ) {
active[u] = true;
for ( int v: adj[u] ) {
if ( active[v] )
orase.unionn( u, v );
}
}
for ( int v: queries[t] ) {
int sz = orase.calcSz( v );
long long sum = orase.calcSum( v );
if ( sz == n )
sePoate[v] = true;
else if ( sum > t ) {
queries[sum].push_back( v );
times.insert( sum );
}
}
}
for ( int v = 1; v <= n; v++ )
cout << sePoate[v];
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
5116 KB |
Output is correct |
2 |
Correct |
2 ms |
4956 KB |
Output is correct |
3 |
Correct |
1 ms |
4956 KB |
Output is correct |
4 |
Incorrect |
4 ms |
5724 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4956 KB |
Output is correct |
2 |
Correct |
1 ms |
5136 KB |
Output is correct |
3 |
Incorrect |
611 ms |
100792 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4952 KB |
Output is correct |
2 |
Runtime error |
588 ms |
170428 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4952 KB |
Output is correct |
2 |
Runtime error |
222 ms |
41428 KB |
Execution killed with signal 11 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
5116 KB |
Output is correct |
2 |
Correct |
2 ms |
4956 KB |
Output is correct |
3 |
Correct |
1 ms |
4956 KB |
Output is correct |
4 |
Incorrect |
4 ms |
5724 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |