Submission #417838

# Submission time Handle Problem Language Result Execution time Memory
417838 2021-06-04T11:35:39 Z Hegdahl Toy Train (IOI17_train) C++17
0 / 100
9 ms 1996 KB
#include <bits/stdc++.h>
#include "train.h"

using namespace std;

const int mxN = 5000;
vector<int> g[mxN], gp[mxN], condensed[mxN];
int a[mxN], r[mxN];

bool all_a = true, all_b = true;

int vis[mxN], scc[mxN];
vector<int> order;
void dfs1(int cur) {
  vis[cur] = 1;
  for (int nxt : g[cur])
    if (!vis[nxt])
      dfs1(nxt);
  order.push_back(cur);
}

void dfs2(int root, int cur) {
  vis[cur] = 1;
  scc[cur] = root;
  for (int nxt : gp[cur])
    if (!vis[nxt])
      dfs2(root, nxt);
}

vector<int> who_wins(vector<int> _a, vector<int> _r, vector<int> u, vector<int> v) {
  const int n = (int)_a.size();
  const int m = (int)u.size();

  for (int i = 0; i < n; ++i)
    a[i] = _a[i];
  for (int i = 0; i < n; ++i)
    r[i] = _r[i];

  for (int i = 0; i < n; ++i) {
    all_a &= a[i];
    all_b &= !a[i];
  }
  assert(all_a);

  for (int i = 0; i < n; ++i)
    g[i].clear();
  for (int i = 0; i < n; ++i)
    gp[i].clear();
  for (int mm = 0; mm < m; ++mm)
    g[u[mm]].push_back(v[mm]);
  for (int mm = 0; mm < m; ++mm)
    gp[v[mm]].push_back(u[mm]);

  fill(vis, vis+n, 0);
  for (int i = 0; i < n; ++i)
    if (!vis[i])
      dfs1(i);
  reverse(order.begin(), order.end());
  fill(vis, vis+n, 0);
  for (int i : order)
    if (!vis[i])
      dfs2(i, i);

  /*
  for (int i = 0; i < n; ++i)
    cerr << scc[i] << " \n"[i==n-1]; // */

  vector<int> e_cnt(n), ans(n);
  for (int mm = 0; mm < m; ++mm)
    e_cnt[scc[u[mm]]] += scc[u[mm]] == scc[v[mm]];

  for (int i = 0; i < n; ++i)
    ans[scc[i]] |= e_cnt[scc[i]] && a[i];

  for (int mm = 0; mm < m; ++mm)
    condensed[scc[v[mm]]].push_back(scc[u[mm]]);

  reverse(order.begin(), order.end());
  for (int i : order) {
    if (scc[i] != i) continue;
    for (int j : condensed[i])
      ans[scc[i]] |= ans[scc[j]];
  }

  for (int i = 0; i < n; ++i)
    ans[i] = ans[scc[i]];

  return ans;
}
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 1612 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 1188 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 1996 KB 3rd lines differ - on the 1st token, expected: '0', found: '1'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 7 ms 1868 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 6 ms 1996 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 4 ms 1612 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -