#include "stations.h"
#include <iostream>
#include <vector>
using namespace std;
vector<int> edge[1000];
vector<int> res(1000, -1);
vector<int> visit(1000, 0);
int dfs(int u, int a, bool flag) //return 1 + largest label yet created
{
visit[u] = 1;
cout << "dfs " << u << ' ' << a << ' ' << flag << '\n';
if(flag == 0)
{
res[u] = a;
a++;
}
for(int v: edge[u])
{
if(visit[v]) continue;
a = dfs(v, a, !flag);
}
if(flag == 1)
{
res[u] = a;
a++;
}
return a;
}
vector<int> label(int n, int k, vector<int> u, vector<int> v)
{
for(int i = 0; i < n-1; i++)
{
edge[u[i]].push_back(v[i]);
edge[v[i]].push_back(u[i]);
}
dfs(0, 0, 0);
vector<int> temp(n);
for(int i = 0; i < n; i++) temp[i] = res[i];
return temp;
}
int find_next_station(int s, int t, vector<int> c)
{
if(s < c[0]) // s is a left label
{
if(t < s) return c.back();
for(int i = 0; i < c.size(); i++) if(t <= c[i]) return c[i];
}
else //s is a right label
{
if(t > s) return c.front();
for(int i = c.size() - 1; 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:56:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
56 | for(int i = 0; i < c.size(); i++) if(t <= c[i]) return c[i];
| ~~^~~~~~~~~~
stations.cpp:63:1: warning: control reaches end of non-void function [-Wreturn-type]
63 | }
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
364 KB |
Execution killed with signal 13 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
364 KB |
Execution killed with signal 13 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
364 KB |
Execution killed with signal 13 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
364 KB |
Execution killed with signal 13 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
364 KB |
Execution killed with signal 13 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |