This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "stations.h"
#include <bits/stdc++.h>
using namespace std;
using ll = int;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll,ll> ii;
typedef vector<ii> vii;
typedef vector<vii> vvii;
#define F first
#define S second
class Solver{
private:
ll k,n,ctr;
vvi adjList;
vi dfs_num, sz, label;
void DFS(ll v){
for (auto u: adjList[v]){
if (dfs_num[u] == -1){
DFS(u);
}
}
dfs_num[v] = ctr++;
label[v] = dfs_num[v]*1000+sz[v];
}
public:
Solver(ll k, ll n, vi u, vi v): k(k), n(n), adjList(n,vi()), dfs_num(n,-1), sz(n,1), label(n){
for (ll i = 0; u.size() > i; i++){
adjList[u[i]].push_back(v[i]);
adjList[v[i]].push_back(u[i]);
}
ctr = 0;
DFS(0);
}
vi get_labels(){
return label;
}
};
vi label(int n, int k, vi u, vi v) {
Solver mySolver(n,k,u,v);
return mySolver.get_labels();
}
int find_next_station(int s, int t, std::vector<int> c) {
ii v = ii(s/1000,s%1000);
ii e = ii(t/1000,t%1000);
vii children(c.size());
for (ll i = 0; c.size() > i; i++){
children[i] = ii(c[i]/1000,c[i]%1000);
}
sort(children.begin(),children.end());
for (ll i = 1; children.size() > i; i++){
if (children[i].F+children[i].S > e.F && e.F >= children[i].F){
return children[i].F*1000+children[i].S;
}
}
return children[0].F*1000+children[0].S;
}
Compilation message (stderr)
stations.cpp: In constructor 'Solver::Solver(ll, ll, vi, vi)':
stations.cpp:30:33: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'll' {aka 'int'} [-Wsign-compare]
30 | for (ll i = 0; u.size() > i; i++){
| ~~~~~~~~~^~~
stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:51:26: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'll' {aka 'int'} [-Wsign-compare]
51 | for (ll i = 0; c.size() > i; i++){
| ~~~~~~~~~^~~
stations.cpp:55:33: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'll' {aka 'int'} [-Wsign-compare]
55 | for (ll i = 1; children.size() > i; i++){
| ~~~~~~~~~~~~~~~~^~~
stations.cpp:48:5: warning: variable 'v' set but not used [-Wunused-but-set-variable]
48 | ii v = ii(s/1000,s%1000);
| ^
# | 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... |