Submission #680843

#TimeUsernameProblemLanguageResultExecution timeMemory
680843aryan12Stations (IOI20_stations)C++17
52.32 / 100
929 ms792 KiB
#include "stations.h" #include <vector> #include <bits/stdc++.h> using namespace std; const int N = 1001; int tin[N], tout[N]; int tim = -1; vector<int> g[N]; void dfs(int node, int par) { tin[node] = ++tim; for(int to: g[node]) { if(to == par) continue; dfs(to, node); } tout[node] = tim; } vector<int> label(int n, int k, vector<int> u, vector<int> v) { tim = -1; for(int i = 0; i < N; i++) { g[i].clear(); } for(int i = 0; i < u.size(); i++) { g[u[i]].push_back(v[i]); g[v[i]].push_back(u[i]); } dfs(0, -1); vector<int> labels; // cout << "in label\n"; for(int i = 0; i < n; i++) { // cout << tin[i] << " " << tout[i] << "\n"; // cout << "label assigned: " << tout[i] * 1000 + tin[i] << "\n"; labels.push_back(tout[i] * 1000 + tin[i]); } return labels; } int find_next_station(int s, int t, std::vector<int> c) { // cout << "find_next_station(" << s << ", " << t << ")\n"; int min_tim_in = 1e9, min_tim_pos = 0; int t_out = t / 1000, t_in = t % 1000; int s_out = s / 1000, s_in = s % 1000; for(int i = 0; i < c.size(); i++) { int time_out = c[i] / 1000, time_in = c[i] % 1000; if(time_in <= t_in && t_out <= time_out && time_in > s_in) { return c[i]; } if(time_in < min_tim_in) { min_tim_in = time_in; min_tim_pos = i; } } return c[min_tim_pos]; }

Compilation message (stderr)

stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:28:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |  for(int i = 0; i < u.size(); i++)
      |                 ~~^~~~~~~~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:50:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |  for(int i = 0; i < c.size(); i++)
      |                 ~~^~~~~~~~~~
stations.cpp:49:6: warning: unused variable 's_out' [-Wunused-variable]
   49 |  int s_out = s / 1000, s_in = s % 1000;
      |      ^~~~~
#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...