Submission #345391

#TimeUsernameProblemLanguageResultExecution timeMemory
345391casperwangTropical Garden (IOI11_garden)C++14
0 / 100
1 ms492 KiB
#include "garden.h"
#include "gardenlib.h"
#include <bits/stdc++.h>
#define All(x) x.begin(), x.end()
#define pb emplace_back
#define pii pair<int,int>
#define ff first
#define ss second
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);
  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[t].pb(i);
    if (tmp[i].size() > 1) {
      t = tmp[i][1];
      t = tmp[t][0] == i ? t+N : t;
      path[t].pb(i+N);
    } else {
      path[t].pb(i+N);
    }
  }
  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 : path[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 : path[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] || (vis1[P] && (G[q] - vis1[i]) % vis1[P] == 0))) {
        ans++;
      } else if (vis2[i] && (vis2[i] == G[q] || (vis2[P+N] && (G[q] - vis2[i]) % vis2[P+N] == 0))) {
        ans++;
      }
    }
    answer(ans);
  }
  return;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...