# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
342397 |
2021-01-02T05:04:17 Z |
Ta180m |
Stations (IOI20_stations) |
C++17 |
|
3000 ms |
484308 KB |
#include "stations.h"
#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;
using ll = long long;
using ii = pair<int, int>;
constexpr int MX = 1e3+5;
int cnt = 1;
int in[MX], out[MX];
vector<int> labels, G[MX];
void dfs(int u, int p, int d) {
in[u] = cnt++;
for (int v : G[u]) if (v != p) dfs(v, u, d+1);
out[u] = cnt++;
if (d%2 == 0) labels[u] = in[u];
else labels[u] = out[u];
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
cnt = 1;
for (int i = 0; i < n; ++i) G[i].clear();
for (int i = 0; i < n-1; ++i) {
G[u[i]].push_back(v[i]);
G[v[i]].push_back(u[i]);
}
labels.clear();
labels.resize(n, 0);
dfs(0, -1, 0);
// for (int x : labels) cout << x << '\n';
vector<int> tmp(begin(labels), end(labels));
sort(begin(tmp), end(tmp));
for (int i = 0; i < labels.size(); ++i)
labels[i] = lower_bound(begin(tmp), end(tmp), labels[i])-begin(tmp);
return labels;
}
int find_next_station(int s, int t, vector<int> c) {
unordered_map<int, int> in, out;
if (s < *min_element(begin(c), end(c))) {
in[s] = s;
for (int i = 0; i < c.size(); ++i) out[c[i]] = c[i];
if (in[s] == 0) {
// s is root
for (int i = 0; i < c.size(); ++i) {
if (t <= out[c[i]]) return c[i];
}
}
else {
int p = *max_element(begin(c), end(c));
c.erase(find(begin(c), end(c), p));
in[c[0]] = in[s]+1;
for (int i = 1; i < c.size(); ++i) in[c[i]] = out[c[i-1]]+1;
out[s] = out[c.back()]+1;
for (int i = 0; i < c.size(); ++i) {
if (t > in[c[i]] && t < out[c[i]]) return c[i];
}
return p;
}
}
else {
out[s] = s;
for (int i = 0; i < c.size(); ++i) in[c[i]] = c[i];
int p = *min_element(begin(c), end(c));
c.erase(find(begin(c), end(c), p));
in[s] = in[c[0]]-1;
for (int i = 0; i < c.size()-1; ++i) out[c[i]] = in[c[i+1]]-1;
out[c.back()] = out[s]-1;
for (int i = 0; i < c.size(); ++i) {
if (t > in[c[i]] && t < out[c[i]]) return c[i];
}
return p;
}
// cout << s << ' ' << t;
// for (int x : c) cout << ' ' << x;
// cout << '\n';
return c.back();
}
Compilation message
stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:35:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | for (int i = 0; i < labels.size(); ++i)
| ~~^~~~~~~~~~~~~~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:44:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
44 | for (int i = 0; i < c.size(); ++i) out[c[i]] = c[i];
| ~~^~~~~~~~~~
stations.cpp:47:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
47 | for (int i = 0; i < c.size(); ++i) {
| ~~^~~~~~~~~~
stations.cpp:55:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
55 | for (int i = 1; i < c.size(); ++i) in[c[i]] = out[c[i-1]]+1;
| ~~^~~~~~~~~~
stations.cpp:57:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
57 | for (int i = 0; i < c.size(); ++i) {
| ~~^~~~~~~~~~
stations.cpp:65:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
65 | for (int i = 0; i < c.size(); ++i) in[c[i]] = c[i];
| ~~^~~~~~~~~~
stations.cpp:69:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
69 | for (int i = 0; i < c.size()-1; ++i) out[c[i]] = in[c[i+1]]-1;
| ~~^~~~~~~~~~~~
stations.cpp:71:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
71 | for (int i = 0; i < c.size(); ++i) {
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3086 ms |
474944 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3068 ms |
473228 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3075 ms |
476144 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3066 ms |
484308 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3088 ms |
478892 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |