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 titi = 0;
lli vis[N];
void dfs(lli u, lli dpth){
// cout << u << ' ';
vis[u] = curVis;
if (dpth % 2 == 1) tk[u] = titi++;
for (auto & i : adj[u]){
if (vis[i] == curVis) continue;
dfs(i, dpth+1);
}
if (dpth % 2 == 0) tk[u] = titi++;
}
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;
titi = 0;
fore(i,0,n-1){
adj[u[i]].pb(v[i]);
adj[v[i]].pb(u[i]);
}
++curVis;
dfs(0, 0);
// cout << ENDL;
return tk;
}
lli find_next_station(lli s, lli t, vi c){
sort(all(c));
// cout << "c: "; for (auto & i : c) cout << i << ' '; cout << ENDL;
bool minor = true;
for (auto & i : c) if (i < s) minor = false;
if (minor){
fore(i,0,sz(c)-1) if (s <= t && t <= c[i]) return c[i];
return c[sz(c)-1];
}
else{
fore(i,1,sz(c)){
lli xx = s;
if ((i + 1) < sz(c)) xx = c[i + 1];
if (c[i] <= t && t <= xx) return c[i];
}
return c[0];
}
return c[sz(c)-1];
}
// void query(lli a, lli b){
// lli xx = 0;
// while (tk[xx] != a) xx++;
// vi c;
// for(auto & i : adj[xx]) c.pb(tk[i]);
// for (auto & i : c) cout << i << ' '; cout << ENDL;
// cout << find_next_station(a, b, c) << ENDL;
// }
// 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);
// // if (t == 1) continue;
// query(3, 15);
// query(2, 15);
// query(16, 15);
// query(11, 15);
// cout << ENDL << "FIN DE CASO" << ENDL << ENDL << ENDL;
// }
// return 0;
// }
# | 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... |