#include"stations.h"
#include<bits/stdc++.h>
using namespace std;
const int N=1005;
vector<int>e[N],a;
int c;
void dfs(int u,int f,int d)
{
if(d)
a[u]=c++;
for(auto v:e[u])
if(v!=f)
dfs(v,u,d^1);
if(!d)
a[u]=c++;
}
vector<int> label(int n,int k,vector<int>u,vector<int>v)
{
a.assign(n,0);
for(int i=0;i<n;i++)
e[i].clear();
c=0;
for(int i=0;i<n-2;i++)
{
e[u[i]].push_back(v[i]);
e[v[i]].push_back(u[i]);
}
dfs(0,0,0);
a[0]=1000;
return a;
}
int find_next_station(int s,int t,vector<int>c)
{
if(c.size()==1)
return c[0];
if(s==1000)
{
for(int i=0;i<c.size()-1;i++)
if(c[i]<=t&&t<c[i+1])
return c[i];
return c.back();
}
else if(s>c.back())
{
for(int i=1;i<c.size()-1;i++)
if(c[i]<=t&&t<c[i+1])
return c[i];
if(c.back()<=t&&t<s)
return c.back();
return c[0];
}
else
{
if(s<t&&t<=c[0])
return c[0];
for(int i=1;i<c.size()-1;i++)
if(c[i-1]<t&&t<=c[i])
return c[i];
return c.back();
}
}
Compilation message
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:38:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
38 | for(int i=0;i<c.size()-1;i++)
| ~^~~~~~~~~~~
stations.cpp:45:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
45 | for(int i=1;i<c.size()-1;i++)
| ~^~~~~~~~~~~
stations.cpp:56:16: 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=1;i<c.size()-1;i++)
| ~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
512 KB |
Invalid labels (duplicates values). scenario=0, label=0 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
384 KB |
Invalid labels (duplicates values). scenario=0, label=0 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
512 KB |
Invalid labels (duplicates values). scenario=1, label=0 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
876 ms |
768 KB |
Output is correct |
2 |
Incorrect |
1 ms |
384 KB |
Invalid labels (duplicates values). scenario=0, label=0 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
512 KB |
Invalid labels (duplicates values). scenario=0, label=0 |
2 |
Halted |
0 ms |
0 KB |
- |