/*
khoi orz, go check out his algo
-normie-
*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int64_t i=0;i < (int64_t)(n);i++)
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define FILE_IN "ninja.inp"
#define FILE_OUT "ninja.out"
#define ofile freopen(FILE_IN,"r",stdin);freopen(FILE_OUT,"w",stdout)
#define fio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define nfio cin.tie(0);cout.tie(0)
#define max(x,y) (((x)>(y))?(x):(y))
#define min(x,y) (((x)<(y))?(x):(y))
#define ord(a,b,c) ((a>=b)and(b>=c))
#define MOD (ll(1000000007))
#define MAX 300001
#define mag 1048576
#define fi first
#define se second
#define pow2(x) (ll(1)<<x)
#define pii pair<int,int>
#define piii pair<int,pii>
#define pll pair<ll,ll>
#define plll pair<ll,pll>
#define For(i,__,___) for(int i=__;i<=___;i++)
#define Rep(i,__,___) for(int i=__;i>=___;i--)
#define ordered_set tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update>
#define endl "\n"
#define bi BigInt
#define ll long long
#define pi 3.1415926535897
//------START-----------//
vector<int> gt[100001];
int used[100001],label_result[100001],t;
//------END-----------//
void dfs1(int x, int parity)
{
used[x]=1;
if (parity==0)
{
label_result[x]=t;
t++;
}
for (int g : gt[x]) if (!used[g])
{
dfs1(g,1-parity);
}
if (parity==1)
{
label_result[x]=t;
t++;
}
}
vector<int> label(int n, int k, vector<int> u, vector<int> v)
{
for (int i=0;i<n-1;i++)
{
gt[u].push_back(v);
gt[v].push_back(u);
}
dfs1(0,0);
vector<int> res;
for (int i=0;i<n;i++)
{
res.push_back(label_result[i]);
}
return res;
}
int find_next_station(int s, int t, vector<int> c)
{
sort(c.begin(),c.end());
if (c.size()==1) return c[0];
else if (s==0)
{
for (int i=c.size()-1;i>=0;i--) if (t<=c[i]) return c[i];
}
else if (s<c[0])
{
if ((t<s)or(t>c[c.size()-2])) return c[c.size()-1];
else for (int i =c.size()-2;i>=0;i--) if (t<=c[i]) return c[i];
}
else
{
if ((t>s)or(t<c[1])) return c[0];
else for (int i =1;i<c.size();i++) if (t>=c[i]) return c[i];
}
}
Compilation message
stations.cpp:8: warning: ignoring #pragma comment [-Wunknown-pragmas]
8 | #pragma comment(linker, "/stack:200000000")
|
stations.cpp: In function 'std::vector<int> label(int, int, std::vector<int>, std::vector<int>)':
stations.cpp:62:7: error: no match for 'operator[]' (operand types are 'std::vector<int> [100001]' and 'std::vector<int>')
62 | gt[u].push_back(v);
| ^
stations.cpp:63:7: error: no match for 'operator[]' (operand types are 'std::vector<int> [100001]' and 'std::vector<int>')
63 | gt[v].push_back(u);
| ^
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:89:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
89 | else for (int i =1;i<c.size();i++) if (t>=c[i]) return c[i];
| ~^~~~~~~~~
stations.cpp:91:1: warning: control reaches end of non-void function [-Wreturn-type]
91 | }
| ^