Submission #309828

#TimeUsernameProblemLanguageResultExecution timeMemory
309828emaborevkovicStations (IOI20_stations)C++14
0 / 100
3048 ms2097156 KiB
#include <iostream> #include <vector> #include <algorithm> using namespace std; #define pb push_back const int N = 1005; vector <int> ls[N]; vector <int> res; int depth[N], podstablo[N]; int dfs (int x, int d, int p) { int suma = 0; depth[x] = d; for (int i=0;i<ls[x].size();i++) { if (ls[x][i] == p) continue; suma += dfs(ls[x][i], d+1, x); } return podstablo[x] = suma+1; } void oznaci (int x, int l, int r, int p) { if (depth[x] % 2 == 0) { res[x] = l; l++; } else { res[x] = r; r--; } for (int i=0;i<ls[x].size();i++) { if (ls[x][i] == p) continue; oznaci(ls[x][i], l, l+podstablo[ls[x][i]]-1, x); l += podstablo[ls[x][i]]; } } vector <int> label (int n, int k, vector <int> u, vector <int> v) { res.resize(n); for (int i=0;i<n-1;i++) { ls[u[i]].pb(v[i]); ls[v[i]].pb(u[i]); } dfs (0, 0, 0); oznaci(0, 0, n-1, 0); return res; } int find_next_station(int s, int t, vector <int> c) { int n = c.size(); if (s == 0) { for (int i=0;i<n;i++) { if (c[i] >= t) return c[i]; } } if (n == 1) return c[0]; if (s < c[0]) { if (t < s || t > c[n-2]) return c[n-1]; for (int i=0;i<n-1;i++) { if (c[i] >= t) return c[i]; } } if (t < c[1] || t > s) return c[0]; for (int i=n-1;i>0;i--) { if (t >= c[i]) return c[i]; } }

Compilation message (stderr)

stations.cpp: In function 'int dfs(int, int, int)':
stations.cpp:17:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |  for (int i=0;i<ls[x].size();i++) {
      |               ~^~~~~~~~~~~~~
stations.cpp: In function 'void oznaci(int, int, int, int)':
stations.cpp:33:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |  for (int i=0;i<ls[x].size();i++) {
      |               ~^~~~~~~~~~~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:69:1: warning: control reaches end of non-void function [-Wreturn-type]
   69 | }
      | ^
#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...