Submission #849351

#TimeUsernameProblemLanguageResultExecution timeMemory
849351IBoryStations (IOI20_stations)C++17
0 / 100
551 ms964 KiB
#include "stations.h" #include <bits/stdc++.h> using namespace std; const int MAX = 1004; vector<int> G[MAX], ans; int in[MAX], out[MAX], dn; void DFS(int cur, int prev, int H) { in[cur] = dn++; for (int next : G[cur]) { if (next == prev) continue; DFS(next, cur, H + 1); } out[cur] = dn++; ans[cur] = ((H & 1) ? out[cur] : in[cur]); } vector<int> label(int N, int K, vector<int> U, vector<int> V) { for (int i = 0; i < N - 1; ++i) { G[U[i]].push_back(V[i]); G[V[i]].push_back(U[i]); } ans.resize(N); DFS(0, -1, 0); vector<int> T; for (int n : ans) T.push_back(n); sort(T.begin(), T.end()); for (int& n : ans) n = lower_bound(T.begin(), T.end(), n) - T.begin(); for (int i = 0; i < N; ++i) G[i].clear(); dn = 0; return ans; } int find_next_station(int S, int T, vector<int> C) { if (S == T) exit(1); sort(C.begin(), C.end()); // S is in, C is out if (S < C[0]) { int pv = S; for (int i = 0; i + 1 < C.size(); ++i) { if (pv <= T && T < C[i]) return C[i]; pv = C[i]; } return C.back(); } // S is out, C is in else { C.push_back(S); for (int i = 1; i + 1 < C.size(); ++i) { if (C[i] <= T && T < C[i + 1]) return C[i]; } return C[0]; } }

Compilation message (stderr)

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