Submission #709934

#TimeUsernameProblemLanguageResultExecution timeMemory
709934raysh07Stations (IOI20_stations)C++17
100 / 100
957 ms932 KiB
#include "stations.h" #include <bits/stdc++.h> using namespace std; #define INF (int)1e9 const int N = 1005; int timer = 0; int tin[N], tout[N]; vector <int> adj[N]; int ans[N]; void dfs(int u, int par = -1, int dist = 0){ tin[u] = ++timer; for (int v: adj[u]){ if (v != par){ dfs(v, u, dist + 1); } } tout[u] = ++timer; if (dist & 1) ans[u] = tout[u]; else ans[u] = tin[u]; } vector<int> label(int n, int k, vector<int> u, vector<int> v) { for (int i=0; i<n-1; i++){ adj[u[i]].push_back(v[i]); adj[v[i]].push_back(u[i]); } dfs(0); int ptr = -1; set <int> st; map <int, int> comp; for (int i=0; i<n; i++) st.insert(ans[i]); for (auto x: st) comp[x] = ++ptr; assert(st.size() == n); vector <int> lab; for (int i=0; i<n; i++) lab.push_back(comp[ans[i]]); for (int i=0; i<n; i++) adj[i].clear(); return lab; } int find_next_station(int s, int t, vector<int> c) { if (s==0){ //root for (auto x: c){ if (x >= t) return x; } assert(false); } if (c.size() == 1) return c[0]; //either s is tin time of u, in which case, rest all are tout times //tout of everything else shud be strictly larger //else s is tout time of u, in which case rest all are tin times //tin of everything else shud be strictly smaller if (s > c[0]){ //this is tout time //rest all are tin time //if t is not in range [c[1], s] its not in subtree if (t < c[1] || t > s) return c[0]; c.push_back(INF); for (int i=2; i<c.size(); i++){ if (c[i] > t) return c[i-1]; } } else { assert(s < c[0]); //now range is [s, c[c.size() - 2] if (t < s || t > c[c.size() - 2]) return c.back(); for (int i=0; i<c.size() - 1; i++){ if (t <= c[i]) return c[i]; } } }

Compilation message (stderr)

In file included from /usr/include/c++/10/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from stations.cpp:2:
stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:39:19: warning: comparison of integer expressions of different signedness: 'std::set<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   39 |  assert(st.size() == n);
      |         ~~~~~~~~~~^~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:71:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |      for (int i=2; i<c.size(); i++){
      |                    ~^~~~~~~~~
stations.cpp:81:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 |      for (int i=0; i<c.size() - 1; i++){
      |                    ~^~~~~~~~~~~~~
stations.cpp:85:1: warning: control reaches end of non-void function [-Wreturn-type]
   85 | }
      | ^
#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...