Submission #640219

# Submission time Handle Problem Language Result Execution time Memory
640219 2022-09-14T02:40:57 Z andecaandeci Stranded Far From Home (BOI22_island) C++17
10 / 100
75 ms 644 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); 
  }
}

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

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 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 55 ms 492 KB Output is correct
5 Correct 49 ms 520 KB Output is correct
6 Correct 71 ms 484 KB Output is correct
7 Correct 50 ms 468 KB Output is correct
8 Correct 35 ms 476 KB Output is correct
9 Correct 50 ms 516 KB Output is correct
10 Correct 42 ms 468 KB Output is correct
11 Correct 40 ms 468 KB Output is correct
12 Correct 27 ms 468 KB Output is correct
13 Correct 75 ms 484 KB Output is correct
14 Correct 27 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 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 1 ms 340 KB Output is correct
2 Runtime error 1 ms 644 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 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 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 55 ms 492 KB Output is correct
5 Correct 49 ms 520 KB Output is correct
6 Correct 71 ms 484 KB Output is correct
7 Correct 50 ms 468 KB Output is correct
8 Correct 35 ms 476 KB Output is correct
9 Correct 50 ms 516 KB Output is correct
10 Correct 42 ms 468 KB Output is correct
11 Correct 40 ms 468 KB Output is correct
12 Correct 27 ms 468 KB Output is correct
13 Correct 75 ms 484 KB Output is correct
14 Correct 27 ms 468 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Runtime error 1 ms 596 KB Execution killed with signal 11
18 Halted 0 ms 0 KB -