Submission #879386

# Submission time Handle Problem Language Result Execution time Memory
879386 2023-11-27T09:28:27 Z vladburac Stranded Far From Home (BOI22_island) C++17
0 / 100
197 ms 20052 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int NMAX = 2e5;

pair<int, int> v[NMAX+1];
vector <int> edges[NMAX+1];
int parent[NMAX+1];
bool viz[NMAX+1];
int marked[NMAX+1];
int sum[NMAX+1];

int findd( int x ) {
  int cop = x;
  bool markedOnWay = false;
  while( parent[cop] != cop ) {
    if( marked[cop] )
      markedOnWay = true;
    cop = parent[cop];
  }
  while( parent[x] != x ) {
    int par = parent[x];
    parent[x] = cop;
    marked[x] = markedOnWay;
    x = par;
  }
  return cop;
}
void unite( int a, int b, int nxtWeight ) {
  int x = findd( a );
  int y = findd( b );
  if( x != y ) {
    parent[x] = y;
    sum[y] += sum[x];
    if( sum[y] < nxtWeight )
      marked[y] = true;
  }
}
void solve() {
  int n, m, i, a, b;
  cin >> n >> m;
  for( i = 0; i < n; i++ ) {
    cin >> v[i].first;
    v[i].second = i;
    parent[i] = i;
    viz[i] = false;
    sum[i] = v[i].first;
  }
  v[n].first = 0;
  for( i = 0; i < m; i++ ) {
    cin >> a >> b;
    a--, b--;
    edges[a].push_back( b );
    edges[b].push_back( a );
  }
  sort( v, v + n );
  for( i = 0; i < n; i++ ) {
    viz[v[i].second] = true;
    bool linked = false;
    for( auto vec: edges[v[i].second] ) {
      if( viz[vec] ) {
        unite( v[i].second, vec, v[i+1].first );
        linked = true;
      }
    }
    if( !linked && v[i].first < v[i+1].first )
      marked[v[i].second] = true;
  }
  for( i = 0; i < n; i++ )
    a = findd( i );
  for( i = 0; i < n; i++ )
    cout << 1 - marked[i];
  cout << "\n";
}
int main() {
  //ios_base::sync_with_stdio( false );
  //cin.tie( NULL );
  //cout.tie( NULL );
  int t = 1;
  //cin >> t;
  while( t-- )
    solve();
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 8540 KB Output is correct
2 Correct 1 ms 8632 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Incorrect 3 ms 8540 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8536 KB Output is correct
2 Correct 1 ms 8536 KB Output is correct
3 Incorrect 174 ms 19992 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8792 KB Output is correct
2 Incorrect 190 ms 20048 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8536 KB Output is correct
2 Incorrect 197 ms 20052 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 8540 KB Output is correct
2 Correct 1 ms 8632 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Incorrect 3 ms 8540 KB Output isn't correct
5 Halted 0 ms 0 KB -