Submission #347870

#TimeUsernameProblemLanguageResultExecution timeMemory
347870milleniumEeeeTropical Garden (IOI11_garden)C++17
Compilation error
0 ms0 KiB
/*
ребра как вершины
*/
#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]; // edge graph
pii from_to[MAXN * 2];
int table[31][MAXN];

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 = 1;
  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};
    }
  }
  for (int v = 0; v < n; v++) {
    for (auto edge : g[v]) {
      int to = edge.fr, ind = edge.sc;
      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 < m; v++) {
        table[pw][v] = eg[v][0];
      }
    } else {
      for (int v = 0; v < m; v++) {
        table[pw][v] = table[pw - 1][table[pw - 1][v]];
      }
    }
  }
  for (int i = 0; i < q; i++) {
    answer(solve(G[i]));
  }
}

Compilation message (stderr)

garden.cpp: In function 'void count_routes(int, int, int, int (*)[2], int, int*)':
garden.cpp:66:25: warning: unused variable 'ind' [-Wunused-variable]
   66 |       int to = edge.fr, ind = edge.sc;
      |                         ^~~
/tmp/ccwtC85h.o: In function `read_input()':
grader.cpp:(.text+0x0): multiple definition of `read_input()'
/tmp/ccr1g78T.o:garden.cpp:(.text+0xa0): first defined here
/tmp/ccwtC85h.o: In function `answer(int)':
grader.cpp:(.text+0x130): multiple definition of `answer(int)'
/tmp/ccr1g78T.o:garden.cpp:(.text+0x1d0): first defined here
/tmp/ccwtC85h.o: In function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/ccr1g78T.o:garden.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status