Submission #345393

#TimeUsernameProblemLanguageResultExecution timeMemory
345393casperwangTropical Garden (IOI11_garden)C++14
0 / 100
1 ms620 KiB
#include <bits/stdc++.h>
#include "garden.h"
#include "gardenlib.h"
#define pb emplace_back
using namespace std;
#define debug(args...) kout("[ " + string(#args) + " ]", args)
void kout() { cerr << endl; }
template <class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ',kout(b...); }
template <class T> void pary(T L, T R) { while (L != R) cerr << *L << " \n"[++L==R]; }
 
const int MAXN = 150000;
const int MAXQ = 2000;
 
void count_routes(int N, int M, int P, int R[][2], int Q, int G[]) {
  vector <vector<int>> tmp(N), path(2*N), repath(2*N);
  for (int i = 0; i < M; i++) {
    tmp[R[i][0]].pb(R[i][1]);
    tmp[R[i][1]].pb(R[i][0]);
  }
  for (int i = 0; i < N; i++) {
    int t = tmp[i][0];
    t = (tmp[t][0] == i ? t+N : t);
    path[i].pb(t);
    repath[t].pb(i);
    if (tmp[i].size() > 1) {
      t = tmp[i][1];
      t = (tmp[t][0] == i ? t+N : t);
      path[i+N].pb(t);
      repath[t].pb(i+N);
    } else {
      path[i+N].pb(t);
      repath[t].pb(i+N);
    }
  }

  int v1 = 1, v2 = 1, now;
  now = path[P][0];
  while (now != P   && v1 < 2*N+1) now = path[now][0], v1++;
  now = path[P+N][0];
  while (now != P+N && v2 < 2*N+1) now = path[now][0], v2++;
  if (v1 == 2*N+1) v1 = 0;
  if (v2 == 2*N+1) v2 = 0;

  vector <int> vis1(2*N), vis2(2*N);
  queue <int> nxt;
  nxt.push(P);
  while (nxt.size()) {
    int now = nxt.front();
    nxt.pop();
    for (int i : repath[now])
      if (!vis1[i])
        vis1[i] = vis1[now]+1, nxt.push(i);
  }
  nxt.push(P+N);
  while (nxt.size()) {
    int now = nxt.front();
    nxt.pop();
    for (int i : repath[now])
      if (!vis2[i])
        vis2[i] = vis2[now]+1, nxt.push(i);
  }

  for (int q = 0; q < Q; q++) {
    int ans = 0;
    for (int i = 0; i < N; i++) {
      if (vis1[i] && (vis1[i] == G[q] || (v1 && (G[q] - vis1[i]) % v1 == 0))) {
        ans++;
      } else if (vis2[i] && (vis2[i] == G[q] || (v2 && (G[q] - vis2[i]) % v2 == 0))) {
        ans++;
      }
    }
    answer(ans);
  }
  return;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...