# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1080639 | thelegendary08 | City (JOI17_city) | C++14 | 368 ms | 59236 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>
#define pb push_back
#define ll long long
#define vi vector<ll>
#define vvi vector<vector<int>>
#define vll vector<long long int>
#define vvll vector<vector<long long int>>
#define pii pair<int, int>
#define vpii vector<pair<int, int>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define mii map<int,int>
#define mll map<long long int, long long int>
#define mivi map<int,vector<int>>
#define f0r(i,n) for(int i=0;i<n;i++)
#define FOR(i,k,n) for(int i=k;i<n;i++)
using namespace std;
const int mxn = 250005;
vi order;
vi adj[mxn];
vb vis(mxn, 0);
vi sz(mxn, 0);
vi code(mxn, 0);
void dfs(int x){
if(vis[x])return;
int cur = 1;
vis[x] = 1;
order.pb(x);
vpii please;
for(auto u : adj[x]){
please.pb({sz[u], u});
}
sort(please.rbegin(), please.rend());
for(auto u : please){
dfs(u.second);
}
}
int getsz(int x, int from){
int cur = 1;
for(auto u : adj[x]){
if(u != from){
cur += getsz(u, x);
}
}
sz[x] = cur;
return cur;
}
void Encode(int n, int a[], int b[])
{
f0r(i, n-1){
adj[a[i]].pb(b[i]);
adj[b[i]].pb(a[i]);
}
getsz(0, -1);
dfs(0);
f0r(i, n){
code[order[i]] = i;
}
for (int i = 0; i < n; ++i) {
ll c;
if(sz[i] < 125000ll) c = 125000ll * code[i] + sz[i];
else c = 125000ll* 250000ll + 250001ll * code[i] + sz[i];
Code(i, c);
//cout<<i<<' '<<sz[i]<<' '<<code[i]<<'\n';
}
}
#include "Device.h"
#define ll long long
void InitDevice()
{
}
int Answer(long long S, long long T)
{
ll szs, cs, szt, ct;
//cout<<S<<' '<<T<<'\n';
if(S >= 250000ll * 125000ll){
S -= 250000ll * 125000ll;
szs = S % 250001ll;
cs = S / 250001ll;
}
else{
szs = S % 125000ll;
cs = S / 125000ll;
}
if(T >= 250000ll * 125000ll){
T -= 250000ll * 125000ll;
szt = T % 250001ll;
ct = T / 250001ll;
}
else{
szt = T % 125000ll;
ct = T/ 125000ll;
}
//cout<<cs<<' '<<ct<<' '<<szs<<' '<<szt<<'\n';
if(cs + szs > ct && ct > cs)return 1;
if(ct + szt > cs && cs > ct)return 0;
return 2;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |