This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
// #pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
#define f first
#define s second
#define fore(i,a,b) for(int i = (a), ThxMK = (b); i < ThxMK; ++i)
#define pb push_back
#define all(s) begin(s), end(s)
#define _ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(s) int(s.size())
#define ENDL '\n'
using namespace std;
typedef long double ld;
typedef int lli;
typedef pair<lli,lli> ii;
typedef vector<lli> vi;
typedef vector<ii> vii;
#define deb(x) cout << #x": " << (x) << endl;
const lli INF = 1e9 + 12;
const lli N = 1e3 + 12;
vector <vi> adj;
vi tk;
lli curVis = 0;
lli id = 0;
lli vis[N];
lli dfs(lli u){
// cout << u << ' ';
vis[u] = curVis;
lli cc = 0;
lli a = INF, b = -INF;
for (auto &i : adj[u]){
if (vis[i] == curVis) continue;
cc++;
lli x = dfs(i);
a = min(a, x % 1000);
b = max(b, lli(x / 1000ll));
}
a = min(a, id);
b = max(b, id);
id++;
// cout << a << ' ' << b << ENDL;
tk[u] = (1000ll * b) + a;
return tk[u];
}
vi label(lli n, lli k, vi u, vi v){
adj.resize(n + 5);
for (auto &i : adj) i.clear();
tk.resize(n);
for (auto &i : tk) i = -1ll;
id = 0;
fore(i,0,n-1){
adj[u[i]].pb(v[i]);
adj[v[i]].pb(u[i]);
}
++curVis;
dfs(0);
// cout << ENDL;
return tk;
}
lli find_next_station(lli s, lli t, vi c){
lli l = s % 1000;
lli r = lli(s / 1000ll);
lli ll = t % 1000;
lli rr = lli(t / 1000ll);
lli father;
for (auto & i : c){
lli a = i % 1000;
lli b = lli(i / 1000ll);
if (a <= l && r <= b) father = i;
}
lli ans = father;
for (auto & i : c){
if (i == father) continue;
lli a = i % 1000;
lli b = lli(i / 1000ll);
if (a <= ll && rr <= b) ans = i;
}
return ans;
}
// int main(){ _
// // freopen("file.in","r",stdin);
// // freopen("file.out","w",stdout);
// vector<vi> vv;
// lli t; cin >> t;
// while (t--){
// lli n, k; cin >> n >> k;
// vi a(n-1); vi b(n-1);
// fore(i,0,n-1) cin >> a[i] >> b[i];
// vi v = label(n, k, a, b);
// for (auto & i : v) cout << i << ' '; cout << ENDL;
// vv.pb(v);
// }
// return 0;
// }
Compilation message (stderr)
stations.cpp: In function 'lli find_next_station(lli, lli, vi)':
stations.cpp:85:10: warning: 'father' may be used uninitialized in this function [-Wmaybe-uninitialized]
85 | return ans;
| ^~~
# | 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... |