답안 #347987

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
347987 2021-01-14T02:03:39 Z milleniumEeee 열대 식물원 (Tropical Garden) (IOI11_garden) C++17
0 / 100
9 ms 11500 KB
/*
ребра как вершины
*/
#include "garden.h"
#include "gardenlib.h"
#include <bits/stdc++.h>
//#include "grader.cpp"
#define pii pair<int, int>
#define fr first
#define sc second
#define pb push_back
#define mk make_pair
#define szof(s) (int)s.size()
using namespace std;
 
const int MAXN = 150005;
int n, m, q, p;
vector <pii> edges;
vector <pii> g[MAXN];
map <pii, int> mp;
vector <int> eg[MAXN * 2]; // edge graph
pii from_to[MAXN * 2];
int table[31][MAXN * 2];
 
int get(int v, int k) {
  int cur = v;
  for (int i = 30; i >= 0; i--) {
    if (k & (1 << i)) {
      cur = table[i][cur];
    }
  }
  return cur;
}
 
int solve(int k) {
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int ind = get(g[i][0].sc, k - 1);
    if (from_to[ind].sc == p) {
      ans++;
    }
  }
  return ans;
}
 
void count_routes(int N, int M, int P, int R[][2], int Q, int G[]) {
  n = N;
  m = M;
  q = Q;
  p = P;
  for (int i = 0; i < m; i++) {
    int x = R[i][0];
    int y = R[i][1];
    edges.pb({x, y});
    if (szof(g[x]) < 2) {
      g[x].pb({y, i});
    }
    if (szof(g[y]) < 2) {
      g[y].pb({x, i});
    }
  }
  int cnt = 0;
  for (int v = 0; v < n; v++) {
    for (auto edge : g[v]) {
      int to = edge.fr, ind = edge.sc;
      mp[{v, to}] = cnt++;
      from_to[cnt - 1] = {v, to};
    }
  }
  int sz = 0;
  for (int v = 0; v < n; v++) {
    for (auto edge : g[v]) {
      int to = edge.fr, ind = edge.sc;
      sz++;
      if (g[to][0].sc != ind) {
        eg[mp[{v, to}]].push_back(mp[{to, g[to][0].fr}]);
        continue;
      }
      if (szof(g[to]) > 1 && g[to][1].sc != ind) {
        eg[mp[{v, to}]].push_back(mp[{to, g[to][1].fr}]);
        continue;
      }
      if (szof(g[to]) == 1) {
        eg[mp[{v, to}]].push_back(mp[{to, v}]);
        continue;
      }
    }
  }
  for (int pw = 0; pw < 30; pw++) {
    if (pw == 0) {
      for (int v = 0; v < sz; v++) {
        table[pw][v] = eg[v][0];
      }
    } else {
      for (int v = 0; v < sz; v++) {
        table[pw][v] = table[pw - 1][table[pw - 1][v]];
      }
    }
  }
  for (int i = 0; i < q; i++) {
    answer(solve(G[i]));
  }
}

Compilation message

garden.cpp: In function 'void count_routes(int, int, int, int (*)[2], int, int*)':
garden.cpp:65:25: warning: unused variable 'ind' [-Wunused-variable]
   65 |       int to = edge.fr, ind = edge.sc;
      |                         ^~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 11500 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 11500 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 11500 KB Output isn't correct
2 Halted 0 ms 0 KB -