Submission #578554

#TimeUsernameProblemLanguageResultExecution timeMemory
578554VanillaStations (IOI20_stations)C++17
52.32 / 100
940 ms880 KiB
#include <bits/stdc++.h> #include "stations.h" using namespace std; const int maxn = 1002; vector <int> ad [maxn]; int ct = 0; int get_mx(int x) { return x / 1000; } int get_nd (int x) { return x % 1000; } bool comp (int a, int b){ return a % 1000 < b % 1000; } int dfs (int u, int p, vector <int> &lb) { lb[u] = ct++; int mx = 0; for (int v: ad[u]) { if (v == p) continue; mx = max(mx, dfs(v, u, lb)); } mx = max(mx, lb[u]); lb[u] += 1000 * mx; return mx; } vector<int> label(int n, int k, vector<int> u, vector<int> v) { vector<int> labels(n); ct = 0; for (int i = 0; i < n; i++){ ad[i].clear(); } for (int i = 0; i < n - 1; i++){ ad[u[i]].push_back(v[i]); ad[v[i]].push_back(u[i]); } dfs(0, -1, labels); // for (int i = 0; i < n; i++){ // cout << i << " " << labels[i] << " " << get_nd(labels[i]) << " " << get_mx(labels[i]) << "\n"; // } return labels; } int find_next_station(int s, int t, vector<int> c) { sort(c.begin(), c.end(), comp); if (get_nd(t) < get_nd(s) || get_mx(s) < get_nd(t)) return c[0]; for (int i = 1; i < c.size(); i++){ if (get_nd(c[i]) == get_nd(t)) return c[i]; if (get_nd(c[i]) > get_nd(t)) return c[i-1]; } return c.back(); }

Compilation message (stderr)

stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:52:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |  for (int i = 1; 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...