Submission #73173

#TimeUsernameProblemLanguageResultExecution timeMemory
73173funcsrToy Train (IOI17_train)C++17
22 / 100
694 ms5524 KiB
#include "train.h"
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <algorithm>
#include <cassert>
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define INF (1LL<<60)
#define _1 first
#define _2 second
using namespace std;
typedef pair<int, int> P;

int N, M;
vector<int> G[5000], R[5000];

vector<int> who_wins(vector<int> owner, vector<int> color, vector<int> U, vector<int> V) {
  N = owner.size(), M = U.size();
  vector<int> used(N);
  rep(i, M) G[U[i]].pb(V[i]), R[V[i]].pb(U[i]);
  bool allA = true, allB = true;
  for (int x : owner) if (x == 0) allA = false; else allB = false;
  queue<int> win;
  if (allA) {
    rep(s, N) if (color[s] == 1) {
      rep(x, N) used[x] = false;
      queue<int> q;
      q.push(s);
      while (!q.empty()) {
        int x = q.front(); q.pop();
        for (int t : G[x]) if (!used[t]) {
          used[t] = true;
          q.push(t);
        }
      }
      if (used[s]) win.push(s);
    }
  }
  else if (allB) {
    rep(s, N) if (color[s] == 0) {
      rep(x, N) used[x] = false;
      queue<int> q;
      q.push(s);
      while (!q.empty()) {
        int x = q.front(); q.pop();
        for (int t : G[x]) if (color[t] == 0 && !used[t]) {
          used[t] = true;
          q.push(t);
        }
      }
      if (used[s]) win.push(s);
    }
  }
  else abort();
  rep(i, N) used[i] = false;

  while (!win.empty()) {
    int x = win.front(); win.pop();
    if (used[x]) continue;
    used[x] = true;
    for (int t : R[x]) win.push(t);
  }
  if (allB) rep(i, N) used[i] ^= 1;
  return used;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...