#include "stations.h"
#include <vector>
#include <algorithm>
using namespace std;
vector<int> adj[1000];
vector<int> labels;
int sub[1000];
void dfs1(int x, int p)
{
sub[x] = 1;
for(int i : adj[x])
{
if(i == p) continue;
dfs1(i, x);
sub[x] += sub[i];
}
}
void dfs2(int x, int p, int d, int l, int r){
if(p != -1 && d == 0) labels[x] = l;
else if(p != -1) labels[x] = r;
int tmp = l;
if(d == 0) tmp++;
for(int i : adj[x])
{
if(i == p) continue;
dfs2(i, x, !d, tmp, tmp + sub[i] - 1);
tmp += sub[i];
}
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
labels.resize(n);
for(int i=0;i<n-1;i++){
adj[u[i]].push_back(v[i]);
adj[v[i]].push_back(u[i]);
}
dfs1(0, -1);
labels[0] = 0;
dfs2(0, -1, 0, 0, n-1);
return labels;
}
int find_next_station(int s, int t, std::vector<int> c) {
sort(c.begin(), c.end());
int n = c.size() - 1;
int m = c[0], M = c[n];
if(m > s)
{
if(t < s || t > M) return M;
for(int i=0;i<=n;i++)
{
if(t <= c[i]) return c[i];
}
}
if(M < s)
{
if(t > s || t < m) return m;
for(int i=n;i>=0;i--)
{
if(t >= c[i]) return c[i];
}
}
}
Compilation message
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:69:1: warning: control reaches end of non-void function [-Wreturn-type]
69 | }
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1919 ms |
2097156 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3069 ms |
400 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1392 ms |
2097156 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1109 ms |
400 KB |
Output is correct |
2 |
Runtime error |
1138 ms |
2097156 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2183 ms |
2097156 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |