Submission #431935

#TimeUsernameProblemLanguageResultExecution timeMemory
431935MeGustaElArroz23Stations (IOI20_stations)C++14
5 / 100
931 ms744 KiB
#include "stations.h" #include <cstdio> #include <cassert> #include <map> #include <vector> #include <algorithm> //////// /////////////////// #include "stations.h" #include<bits/stdc++.h> using namespace std; #define fi first #define se second typedef long long ll; typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int,int> pii; typedef vector<pii> vii; typedef vector<vii> vvii; typedef vector<bool> vb; int tiempo; vvi conexiones; vi labeles; void bfs(int ac, int ant, bool entrada){ tiempo++; //cerr << ac << ' ' << tiempo << '\n'; if (entrada) labeles[ac]=tiempo; for (int x:conexiones[ac]){ if (x!=ant){ bfs(x,ac,not entrada); } } tiempo++; //cerr << ac << ' ' << tiempo << '\n'; if (not entrada) labeles[ac]=tiempo+2000; } std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) { //cerr<<"h"; vi res(n); conexiones=vvi(n); cerr<<0; for (int i=0;i<n-1;i++){ conexiones[u[i]].push_back(v[i]); conexiones[v[i]].push_back(u[i]); } cerr<<0; int i=0; while (conexiones[i].size()==2) i++; cerr<<0; int ant=-1; for (int j=0;j<n;j++){ res[i]=j; swap(i,ant); for (int x:conexiones[ant]){ if (x!=i){ i=x; break; } } } return res; tiempo=-1; conexiones=vvi(n); for (int i=0;i<n-1;i++){ conexiones[u[i]].push_back(v[i]); conexiones[v[i]].push_back(u[i]); } labeles=vi(n); bfs(0,-1, 1); //for (int x:labeles) cerr << x << ' '; //cerr<<'\n'; return labeles; } int find_next_station(int ac, int obj, std::vector<int> vecinos) { if (obj>ac) return ac+1; else return ac-1; obj%=2000; bool entrada=(ac<2000); ac%=2000; sort(vecinos.begin(),vecinos.end()); if (vecinos.size()==1) return vecinos[0]; //arriba if (entrada){ int izq=ac; if (obj<izq) return vecinos[vecinos.size()-1]; //arriba for (int x:vecinos){ if (x%2000>=obj) return x; //abajo } return vecinos[vecinos.size()-1]; //arriba } else{ int der=ac; if (obj>der) return vecinos[0]; //arriba for (int i=vecinos.size()-1;i>=0;i--){ int x=vecinos[i]; if (x%2000<=obj) return x; //abajo } return vecinos[0]; //arriba } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...