# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
996902 | AdamGS | City (JOI17_city) | C++17 | 257 ms | 39936 KiB |
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 "Encoder.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const ll K=396736;
const int LIM=25e4+7;
vector<int>V[LIM];
ll pre[LIM], lpre;
ll rnd(ll x) {
if(x<=50) return x;
x-=50;
ll po=0, ko=1000000000;
while(po<ko) {
ll sr=(po+ko)/2;
if(sr*sr<x) po=sr+1; else ko=sr;
}
return po*po+50;
}
ll cod(ll x) {
if(x<=50) return x;
x-=50;
ll po=0, ko=1000000000;
while(po<ko) {
ll sr=(po+ko)/2;
if(sr*sr<x) po=sr+1; else ko=sr;
}
return po+50;
}
void DFS(int x, int o) {
pre[x]=lpre; ++lpre;
for(auto i : V[x]) if(i!=o) DFS(i, x);
ll z=lpre-pre[x];
lpre=pre[x]+rnd(z);
Code(x, pre[x]+K*cod(z));
}
void Encode(int n, int A[], int B[]) {
rep(i, n-1) {
V[A[i]].pb(B[i]);
V[B[i]].pb(A[i]);
}
DFS(0, 0);
}
#include "Device.h"
#include<bits/stdc++.h>
typedef long long ll;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const ll K=396736;
void InitDevice() {}
ll dec(ll x) {
if(x<=50) return x;
x-=50;
return x*x+50;
}
bool oc(ll x, ll y) {
ll a=x%K, b=y%K, c=x/K;
return a<=b && b<a+dec(c);
}
int Answer(ll S, ll T) {
if(oc(S, T)) return 1;
if(oc(T, S)) return 0;
return 2;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |