Submission #928804

#TimeUsernameProblemLanguageResultExecution timeMemory
928804KitasCraftStations (IOI20_stations)C++17
Compilation error
0 ms0 KiB
#include "stations.h" #include <iostream> #include <vector> #include <algorithm> #include <iterator> using namespace std; const int MAXN = 1e3; int p[MAXN],sub[MAXN]; vector<int> ed[MAXN]; // dfs for counting subtree size void dfs(const int &v) { sub[v]=1; for (const int &i : ed[v]) { if (i == p[v]) continue; p[i]=v; dfs(i); sub[v]+=sub[i]; } } // construct the labelling while bringing the labels // the node, min label in subtree, max label in the subtree, is current node with max label (true) or min label (false) void con(const int &v,int l,const int &r,const bool &maks,vector<int> &lab) { if (maks) { // label v with max lab[v]=r; } else { // label v with min lab[v]=l; l++; } for (const int &i : ed[v]) { if (i == p[v]) continue; con(i,l,l+sub[i]-1,1-maks,lab); l+=sub[i]; } } vector<int> label(int n, int k, vector<int> u, vector<int> v) { vector<int> perm(n,0); for (int i=0;i<n-1;i++) { ed[u[i]].pb(v[i]); ed[v[i]].pb(u[i]); } p[0]=-1; dfs(0); con(0,0,n-1,0,perm); return perm; } int find_next_station(int s, int t, vector<int> c) { int x=c.size(); if (x == 1) return c[0]; if (s < c[0]) { // this node is labeled min if (t < s || t > c[k-2]) return c[k-1]; // thank you for making array c already sorted lmao return *lower_bound(c.begin(),c.end(),t); } else { // this node is labeled max if (t > s || t < c[1]) return c[0]; return *(--upper_bound(c.begin(),c.end(),t)); } }

Compilation message (stderr)

stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:47:14: error: 'class std::vector<int>' has no member named 'pb'
   47 |     ed[u[i]].pb(v[i]);
      |              ^~
stations.cpp:48:14: error: 'class std::vector<int>' has no member named 'pb'
   48 |     ed[v[i]].pb(u[i]);
      |              ^~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:62:22: error: 'k' was not declared in this scope
   62 |   if (t < s || t > c[k-2]) return c[k-1];
      |                      ^