Submission #640564

# Submission time Handle Problem Language Result Execution time Memory
640564 2022-09-15T00:46:18 Z kith14 Stranded Far From Home (BOI22_island) C++17
10 / 100
75 ms 596 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define db double
#define pairll pair<ll,ll>
#define lpairll pair<ll,pairll>

#define repp(i,a,b) for (ll i = a; i <= b; i++)
#define repz(i,a,b) for (ll i = a; i < b; i++)
#define repm(i,a,b) for (ll i = a; i >= b; i--)
#define fr first
#define sc second
#define mp make_pair
#define pb push_back

const ll N = 2e3+5, MOD = 1e9+7;
ll tc = 1, n, m, ar[N], br[N], vs[N];
ll x, y, k;
string s, s1, s2, ye = "YES", no = "NO";
vector<pairll> v;
vector<ll> ed[N];

void input(){
  cin >> n >> m;
  repp(i,1,n) cin >> ar[i];
  repp(i,1,m){
    cin >> x >> y;
    ed[x].pb(y);
    ed[y].pb(x);
  }
}

void sub1(){
  repp(i,1,n){
    ll cur = ar[i], vst = 1;
    priority_queue<pairll, vector<pairll>, greater<pairll> > pq;
    queue<ll> q;
    q.push(i);
    vs[i] = i;
    while(q.size()){
      ll a = q.front();
      //cout << i << " " << a << endl;
      q.pop();
      for (auto nx : ed[a]){
        if (vs[nx] == i) continue;
        if (ar[nx] > cur){
          pq.push(mp(ar[nx],nx));
        }
        else{
          cur += ar[nx];
          vs[nx] = i;
          q.push(nx);
          vst++;
        }
      }
      while(pq.size() && pq.top().fr <= cur){
        pairll a = pq.top();
        pq.pop();
        cur += a.fr;
        vs[a.sc] = i;
        q.push(a.sc);
        vst++;
      }
    } 
    cout << (vst == n); 
  }
}

ll sub[N], pos[N];
void dfs(ll idx, ll par){
  sub[idx] = ar[idx];
  for (auto i : ed[idx]){
    if (i == par) continue;
    dfs(i,idx);
    sub[idx] += sub[i];
  }
}

void ser(ll idx, ll par){
  for (auto i : ed[idx]){
    if (i == par) continue;
    if (sub[i] >= ar[idx]){
      pos[i] = 1;
      dfs(i,idx);
    }
  }
}

void sub2(){
  //root is at 1
  dfs(1,-1);
  pos[1] = 1;
  ser(1,-1);
  repp(i,1,n) cout << pos[i];
  cout << endl;
}

void solve(){
  if (n <= 2e3 && m <= 2e3) sub1();
  else sub2();
}

int main(){
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  //cin >> tc;
  while(tc--){
    input();
    solve();
  }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 55 ms 468 KB Output is correct
5 Correct 52 ms 596 KB Output is correct
6 Correct 73 ms 388 KB Output is correct
7 Correct 49 ms 468 KB Output is correct
8 Correct 34 ms 504 KB Output is correct
9 Correct 52 ms 532 KB Output is correct
10 Correct 44 ms 388 KB Output is correct
11 Correct 44 ms 496 KB Output is correct
12 Correct 31 ms 468 KB Output is correct
13 Correct 75 ms 476 KB Output is correct
14 Correct 30 ms 440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Runtime error 1 ms 596 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Runtime error 1 ms 596 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 372 KB Output is correct
2 Runtime error 1 ms 596 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 55 ms 468 KB Output is correct
5 Correct 52 ms 596 KB Output is correct
6 Correct 73 ms 388 KB Output is correct
7 Correct 49 ms 468 KB Output is correct
8 Correct 34 ms 504 KB Output is correct
9 Correct 52 ms 532 KB Output is correct
10 Correct 44 ms 388 KB Output is correct
11 Correct 44 ms 496 KB Output is correct
12 Correct 31 ms 468 KB Output is correct
13 Correct 75 ms 476 KB Output is correct
14 Correct 30 ms 440 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 0 ms 384 KB Output is correct
17 Runtime error 1 ms 596 KB Execution killed with signal 11
18 Halted 0 ms 0 KB -