This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// TODO -> PONER ALGO AQUI
// amigos y no mas
// I'm in the coolest driver high
// += O(logn) ; + = O(n)
#include <bits/stdc++.h>
#include "stations.h"
#include <variant>
#define fastio ios_base::sync_with_stdio(0); cin.tie(0)
#define ones(x) __builtin_popcount(x)
#define loga2(x) __builtin_ctzll(x)
#define pos2(x) __builtin_clzll(x)
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef pair <ii, ii> iiii;
typedef vector <int> vi;
typedef vector <ii> vii;
const int mod = 998244353;
const ll inf = (1LL<<62)-1;
struct HASH{
size_t operator()(const pair<int,int>&x)const{
return hash<long long>()(((long long)x.first)^(((long long)x.second)<<32));
}
};
vector< vector<int> > G;
vector<int> order;
vector<bool> vis;
int N;
int cont = 0;
void dfs(int x){
for(int i=0; i<G[x].size(); i++){
int &y = G[x][i];
if(!vis[y]){
vis[y] = true;
dfs(y);
}
}
order[x] = cont; cont++;
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
N = n;
vector<int> labels(n);
G.clear();
order.clear();
vis.clear();
G.resize(n);
order.resize(n);
vis.resize(n,0);
for(int i=0; i<n-1;i++){
G[u[i]].push_back(v[i]);
G[v[i]].push_back(u[i]);
}
vis[0] = true;
dfs(0);
for (int i = 0; i < n; i++) {
labels[i] = order[i];
}
return labels;
}
int find_next_station(int s, int t, std::vector<int> c) {
if(c.size() == 1) return c[0];
if(s < t){
auto it = upper_bound(c.begin() , c.end() , s);
if(it == c.end()) it--;
return *it;
}
// else t<s
auto it = lower_bound(c.begin() , c.end() , s);
if(it!=c.begin()) it--;
return *it;
}
Compilation message (stderr)
stations.cpp: In function 'void dfs(int)':
stations.cpp:40:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
40 | for(int i=0; i<G[x].size(); i++){
| ~^~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |