Submission #306866

#TimeUsernameProblemLanguageResultExecution timeMemory
306866Ruxandra985Stations (IOI20_stations)C++14
100 / 100
1041 ms1280 KiB
#include <bits/stdc++.h> #include "stations.h" #define DIMN 1010 using namespace std; int poz; int lab[DIMN] , last[DIMN] , niv[DIMN]; vector <int> ww[DIMN]; void dfs (int nod , int tt , int lvl){ int i , vecin; //printf ("%d ", nod); if (lvl % 2 == 0) poz++; lab[nod] = poz; niv[nod] = lvl; for (i = 0 ; i < ww[nod].size() ; i++){ vecin = ww[nod][i]; if (vecin != tt){ dfs (vecin , nod , lvl + 1); } } if (lvl % 2 == 1) poz++; last[nod] = poz; } vector<int> label(int n, int k, vector<int> u, vector<int> v) { vector<int> labels; labels.resize(n); for (int i = 0 ; i < n ; i++) ww[i].clear(); for (int i = 0; i <= n - 2; i++) { ww[u[i]].push_back(v[i]); ww[v[i]].push_back(u[i]); } poz = -1; dfs (0 , -1 , 0); for (int i = 0 ; i < n ; i++){ if (niv[i] % 2 == 0) labels[i] = lab[i]; else labels[i] = last[i]; } return labels; } int find_next_station(int s, int t, vector<int> c) { int i; if (c.size() == 1) return c[0]; if (s == 0){ /// incep din 0, e nivel par oricum for (i = 0 ; i <= c.size() - 1 ; i++){ if (c[i] < t && t <= c[i + 1]) return c[i + 1]; } return c[0]; } else { /// unul dintre vecini e clar tatal if (s < c[0]){ /// s e un nivel par if (s <= t && t <= c[0]) return c[0]; for (i = 0 ; i <= c.size() - 2 ; i++){ if (c[i] < t && t <= c[i + 1]) return c[i + 1]; } return c.back(); } else { /// s e un nivel impar for (i = 1 ; i < c.size() - 1 ; i++){ if (c[i] <= t && t < c[i + 1]){ return c[i]; } } if (t >= c.back() && t < s) return c.back(); return c[0]; } } }

Compilation message (stderr)

stations.cpp: In function 'void dfs(int, int, int)':
stations.cpp:21:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |     for (i = 0 ; i < ww[nod].size() ; i++){
      |                  ~~^~~~~~~~~~~~~~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:69:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   69 |         for (i = 0 ; i <= c.size() - 1 ; i++){
      |                      ~~^~~~~~~~~~~~~~~
stations.cpp:84:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   84 |             for (i = 0 ; i <= c.size() - 2 ; i++){
      |                          ~~^~~~~~~~~~~~~~~
stations.cpp:95:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   95 |             for (i = 1 ; i < c.size() - 1 ; 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...