# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
347204 |
2021-01-12T11:15:33 Z |
blue |
Stations (IOI20_stations) |
C++17 |
|
0 ms |
0 KB |
#include "stations.h"
#include <vector>
using namespace std;
vector<int> edge[1000];
vector<int> subtree(1000, 0);
vector<int> res;
void dfs1(int u)
{
subtree[u] = 1;
for(int v: edge[u])
{
if(subtree[v]) continue;
dfs(v);
subtree[u] += subtree[v];
}
}
// left/right, lower limit, upper limit
void dfs2(int u, bool flag, int a, int b)
{
if(flag == 0)
{
res[u] = a;
a++;
}
else
{
res[u] = b;
b--;
}
for(int v: edge[u])
{
if(res[v] != -1) continue;
dfs2(v, !flag, a, a + subtree[v] - 1);
a += subtree[v];
}
}
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]);
}
res = vector<int>(n, -1);
dfs1(1);
dfs2(1, 0, 0, n-1);
return res;
}
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];
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];
return c[i];
}
}
Compilation message
stations.cpp: In function 'void dfs1(int)':
stations.cpp:15:9: error: 'dfs' was not declared in this scope; did you mean 'dfs1'?
15 | dfs(v);
| ^~~
| dfs1
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:68:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
68 | for(int i = 0; i < c.size(); i++) if(t <= c[i]) return c[i];
| ~~^~~~~~~~~~
stations.cpp:69:18: error: 'i' was not declared in this scope
69 | return c[i];
| ^
stations.cpp:75:18: error: 'i' was not declared in this scope
75 | return c[i];
| ^