Submission #347996

# Submission time Handle Problem Language Result Execution time Memory
347996 2021-01-14T02:50:39 Z milleniumEeee Tropical Garden (IOI11_garden) C++17
Compilation error
0 ms 0 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;
}

pii para(int pos) {
  int x = from_to[pos].fr, y = from_to[pos].sc;
  pii res = {min(x, y), max(x, y)};
  return res;
}

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};
      edge.sc = cnt - 1;
    }
  }
  int sz = 0;
  
  for (int v = 0; v < n; v++) {
    for (auto edge : g[v]) {
      int to = edge.fr, ind = edge.sc;
      sz++;
      if (szof(g[to]) == 1) {
        eg[ind].pb(mp[{to, v}]);
        continue;
      }
      pii cur = para(ind);
      pii mn1 = para(mp[{to, g[to][0].fr}]);
      pii mn2 = para(mp[{to, g[to][1].fr}]);  
      if (cur != mn1) {
        eg[ind].pb(mp[{to, g[to][0].fr}]);
      } else {
        eg[ind].pb(mp[{to, g[to][1].fr}]);
      }
    }
  }
  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]));
  }
}


//static int N, M, P, Q;
//static int R[MAXN][2];
//static int G[MAXN];

//signed main() {
  //cin >> N >> M >> P;
  //for (int i = 0; i < M; i++) {
    //cin >> R[i][0] >> R[i][1];
  //}
  //cin >> Q;
  //for (int i = 0; i < Q; i++) {
    //cin >> G[i];
  //}
  //count_routes(N, M, P, R, Q, G);
//}

Compilation message

garden.cpp: In function 'void count_routes(int, int, int, int (*)[2], int, int*)':
garden.cpp:71:25: warning: unused variable 'ind' [-Wunused-variable]
   71 |       int to = edge.fr, ind = edge.sc;
      |                         ^~~
garden.cpp:89:11: warning: variable 'mn2' set but not used [-Wunused-but-set-variable]
   89 |       pii mn2 = para(mp[{to, g[to][1].fr}]);
      |           ^~~
/tmp/cc80Jycu.o: In function `read_input()':
grader.cpp:(.text+0x0): multiple definition of `read_input()'
/tmp/cclObEGg.o:garden.cpp:(.text+0xa0): first defined here
/tmp/cc80Jycu.o: In function `answer(int)':
grader.cpp:(.text+0x130): multiple definition of `answer(int)'
/tmp/cclObEGg.o:garden.cpp:(.text+0x1d0): first defined here
/tmp/cc80Jycu.o: In function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/cclObEGg.o:garden.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status