답안 #417845

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
417845 2021-06-04T11:54:48 Z Hegdahl 장난감 기차 (IOI17_train) C++17
11 / 100
46 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);
}

void dfs3(vector<int> &ans, int cur) {
  ans[cur] = 0;
  vis[cur] = 1;
  for (int nxt : gp[cur])
    if (!vis[nxt]) dfs3(ans, 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_b);

  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)
    if (r[v[mm]] == 0)
      g[u[mm]].push_back(v[mm]);
  for (int mm = 0; mm < m; ++mm)
    if (r[v[mm]] == 0)
      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);

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

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

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

  for (int i = 0; i < n; ++i) { 
    if (scc[i] != i) continue;
    if (e_cnt[i] && r[i] == 0) ans[i] = 0;
  }

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

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

  for (int i = 0; i < n; ++i)
    gp[i].clear();
  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] && ans[i]==0)
      dfs3(ans, i);

  return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 4 ms 1612 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 1100 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 7 ms 1996 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 1392 KB Output is correct
2 Correct 39 ms 1692 KB Output is correct
3 Correct 40 ms 1732 KB Output is correct
4 Correct 40 ms 1732 KB Output is correct
5 Correct 40 ms 1800 KB Output is correct
6 Correct 40 ms 1772 KB Output is correct
7 Correct 41 ms 1744 KB Output is correct
8 Correct 43 ms 1908 KB Output is correct
9 Correct 40 ms 1492 KB Output is correct
10 Correct 39 ms 1652 KB Output is correct
11 Correct 39 ms 1600 KB Output is correct
12 Correct 41 ms 1680 KB Output is correct
13 Correct 46 ms 1840 KB Output is correct
14 Correct 40 ms 1740 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 7 ms 1996 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 4 ms 1612 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -