Submission #900407

#TimeUsernameProblemLanguageResultExecution timeMemory
900407nguyentunglamStations (IOI20_stations)C++17
100 / 100
600 ms10052 KiB
#include "stations.h" #include <vector> #include<bits/stdc++.h> using namespace std; const int N = 1e5 + 10; int st[N], ed[N], t[N], f[N], order[N], timer; vector<int> adj[N]; void dfs(int u, int p) { st[u] = ++timer; for(int &v : adj[u]) if (v != p) { t[v] = t[u] ^ 1; dfs(v, u); } ed[u] = timer; if (!t[u]) f[u] = st[u]; else f[u] = ed[u]; } std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) { for(int i = 0; i < n; i++) adj[i].clear(), st[i] = ed[i] = 0; for(int i = 0; i < u.size(); i++) { adj[u[i]].push_back(v[i]); adj[v[i]].push_back(u[i]); } timer = -1; dfs(0, -1); // if (st[0]) assert(0); for(int i = 0; i < n; i++) order[i] = i; sort(order, order + n, [] (const int &x, const int &y) { if (f[x] != f[y]) return f[x] < f[y]; if (t[x] && t[y]) return st[x] > st[y]; return t[x] < t[y]; }); vector<int> labels(n); timer = 0; for(int cur = 0; cur < n; cur++) { int i = order[cur]; labels[i] = timer++; } // cout << st[3] << endl; // cout << "labels :"; for(int i = 0; i < n; i++) cout << labels[i] << " "; cout << endl; //// cout << ed[1] << endl; // for(int i = 0; i < n; i++) cout << st[i] << " "; cout << endl; // for(int i = 0; i < n; i++) cout << ed[i] << " "; cout << endl; //// cout << st[0] << endl; // cout << endl; return labels; } int find_next_station(int s, int t, std::vector<int> c) { // for(int &j : c) cout << j << " "; cout << endl; if (c.size() == 1) return c.back(); if (!s) { for(int &v : c) if (v >= t) return v; assert(0); } if (s <= c[0]) { // st - ed // cout << 11 << endl; if (s <= t && t <= c.back()) { int ret = 1e9; for(int &v : c) if (v >= t) ret = min(ret, v); return ret; } return c.back(); } else { // ed - st // cout << 22 << endl; // cout << c[1] << " " << s << " " << t << endl; if (c[1] <= t && t <= s) { int ret = 0; for(int &v : c) if (v <= t) ret = max(ret, v); // cout << ret << endl; return ret; } return c[0]; } }

Compilation message (stderr)

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