# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
309712 |
2020-10-04T11:19:06 Z |
kris01 |
Stations (IOI20_stations) |
C++14 |
|
3000 ms |
2097156 KB |
#include "stations.h"
#include <bits/stdc++.h>
#define pii pair <int,int>
#define mp make_pair
using namespace std;
vector < vector <int> > Adj; // Adjacency List for the graph
vector <int> Tin,Tout; // Entry and Exit times respectively
vector <int> Depth; // Depth of a given node from the root (node 1)
int timer = 0;
void DFS(int v,int p) {
Tin[v] = timer++;
for (int x : Adj[v]) {
if (x == p) continue;
Depth[x] = Depth[v] + 1;
DFS(x,v);
}
Tout[v] = timer++;
}
std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
std::vector<int> labels(n);
Adj.resize(n);
Tin.resize(n);
Tout.resize(n);
Depth.resize(n+1,0);
for (int i = 0;i < n-1;i++) {
int a = u[i];
int b = v[i];
Adj[a].push_back(b);
Adj[b].push_back(a);
}
timer = 0;
DFS(0,-1);
vector <pair <int,int> > LBLS(n); // Dummy vector to sort the labels
for (int i = 0;i < n;i++) {
if (Depth[i] % 2 == 0) {
LBLS[i] = mp(Tin[i],i);
} else {
LBLS[i] = mp(Tout[i],i);
}
}
sort(LBLS.begin(),LBLS.end());
for (int i = 0;i < n;i++) {
labels[LBLS[i].second] = i;
}
return labels;
}
int find_next_station(int s, int t, std::vector<int> c) {
sort(c.begin(),c.end());
if (s < c[0]) {
if (t < s || c.size() == 1 || t > c[c.size() - 2])
return c.back();
return *lower_bound(c.begin(), c.end(), t);
} else {
auto it = upper_bound(c.begin(),c.end(),t);
if (c.size() == 1 || t > s || t < c[1]) {
return c[0];
}
return *(upper_bound(c.begin(), c.end(), t) - 1);
}
}
Compilation message
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:57:12: warning: variable 'it' set but not used [-Wunused-but-set-variable]
57 | auto it = upper_bound(c.begin(),c.end(),t);
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
376 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3065 ms |
1776 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1686 ms |
2097156 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
865 ms |
900 KB |
Output is correct |
2 |
Runtime error |
1379 ms |
2097156 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2916 ms |
2097156 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |