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>
#pragma GCC optimize("O2")
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
#define debug(x) {cerr<<#x<<"="<<x<<"\n";}
#define debug2(x, y) {cerr<<"{"<<#x<<", "<<#y<<"}={"<<x<<", "<<y<<"}\n";}
#define debugp(p) {cerr<<#p<<"={"<<p.first<<", "<<p.second<<"}\n";}
#define debugv(abcd) {cerr<<#abcd<<": "; for (auto dcba:abcd) cerr<<dcba<<", ";cerr<<"\n";}
#define pb push_back
#define all(x) x.begin(), x.end()
#define SZ(x) ((int)x.size())
const int inf=1000000100; // 1e9
const ll INF=10000000001000000; // 1e16
const int mod=1000000007;
const int MAXN=1010;
int n, m, k, x, y, a, b, t, ans;
int stt[MAXN], fnt[MAXN], timer;
vi G[MAXN];
void dfs(int node, int par){
stt[node]=timer++;
for (int v:G[node]) if (v!=par) dfs(v, node);
fnt[node]=timer;
}
vi label(int _n, int _k, vi U, vi V){
n=_n;
k=_k;
vi out(n);
for (int i=0; i<n; i++) G[i].clear();
for (int i=0; i<n-1; i++){
int u=U[i], v=V[i];
G[u].pb(v);
G[v].pb(u);
}
timer=0;
dfs(0, 0);
for (int i=0; i<n; i++) out[i]=stt[i]*1000+fnt[i]-1;
return out;
}
int find_next_station(int s, int t, vi adj){
// cerr<<"\n";
// debug2(s, t)
sort(all(adj));
for (int x:adj) if (x==t) return x;
int stt_s=(s)/1000, fnt_s=(s)%1000+1;
int stt_t=(t)/1000, fnt_t=(t)%1000+1;
if (stt_t<stt_s || fnt_s<=stt_t) return adj[0];
// debug2(stt_t, fnt_t)
for (int i=0; i<SZ(adj); i++){
int v=adj[i];
int stt_v=(v)/1000, fnt_v=(v)%1000+1;
if (stt_v<stt_s) continue ; // v=par[s]
// debug2(stt_v, fnt_v)
if (stt_v<=stt_t && stt_t<fnt_v) return v;
}
return -1;
}
Compilation message (stderr)
stations.cpp: In function 'int find_next_station(int, int, vi)':
stations.cpp:55:22: warning: unused variable 'fnt_t' [-Wunused-variable]
55 | int stt_t=(t)/1000, fnt_t=(t)%1000+1;
| ^~~~~
# | 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... |