Submission #565167

#TimeUsernameProblemLanguageResultExecution timeMemory
565167Ronin13Stations (IOI20_stations)C++14
100 / 100
855 ms828 KiB
#include "stations.h" #include <vector> #include <bits/stdc++.h> #define ll long long #define f first #define s second #define pii pair<int,int> #define pll pair<ll,ll> #define pb push_back #define epb emplace_back #define ull unsigned ll using namespace std; const int inf = 1e9 + 1; const ll linf = 1e18 + 1; const int NMAX = 1001; vector <vector <int> > g (NMAX); vector <int> col(NMAX); int timer = 0; vector <int> t_in(NMAX); vector <int> t_out(NMAX); void dfs(int v, int e = -1){ t_in[v] = timer++; for(int to : g[v]){ if(to == e) continue; col[to] = 1 ^ col[v]; dfs(to, v); } t_out[v] = timer++; } std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) { for(int v = 0; v < n; v++){ t_in[v] = t_out[v] = col[v] = 0; g[v].clear(); timer = 0; } std::vector<int> labels(n); for(int i = 0; i < n - 1; i++){ int uu = u[i], vv = v[i]; g[uu].pb(vv); g[vv].pb(uu); } dfs(0); vector <pii> vec; for(int i = 0; i < n; i++){ if(col[i] == 0) vec.pb({t_in[i], i}); else vec.pb({t_out[i], i}); } sort(vec.begin(), vec.end()); int ind = 0; for(auto to : vec){ int x = to.f, y = to.s; labels[y] = ind++; } return labels; } int find_next_station(int s, int t, std::vector<int> c) { bool bl = false; if(c[0] > s) bl = true; if(bl){ sort(c.begin(), c.end()); if(t >= c.back()) return c.back(); //if(c[0] >= t ) return c.back(); if(t < s) return c.back(); for(int i = c.size() - 1 ; i >= 0; i--){ if(c[i] < t) return c[i + 1]; } return c[0]; } else{ sort(c.begin(), c.end()); /*for(int to : c){ cout << to << " "; }*/ if(t > s) return c[0]; if(t <= c[0]) return c[0]; //if(c.back() <= t) return c[0]; for(int i = 0; i < c.size(); i++){ if(c[i] > t) return c[i - 1]; } return c.back(); } }

Compilation message (stderr)

stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:57:13: warning: unused variable 'x' [-Wunused-variable]
   57 |         int x = to.f, y = to.s;
      |             ^
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:84:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   84 |         for(int i = 0; i < c.size(); i++){
      |                        ~~^~~~~~~~~~
#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...