제출 #99344

#제출 시각아이디문제언어결과실행 시간메모리
99344TadijaSebezCity (JOI17_city)C++11
100 / 100
399 ms35336 KiB
#include "Encoder.h" #define ll long long const int N=250050*2; const int M=2*N; int fir[N],go[M],tot,f[M]; void Add(int u, int v){ tot++;f[tot]=v;go[tot]=fir[u];fir[u]=tot;} void AddEdge(int u, int v){ Add(u,v);Add(v,u);} int lid[N],rid[N],tid; void DFS(int u, int p) { lid[u]=tid++; for(int i=fir[u];i;i=go[i]) if(f[i]!=p) DFS(f[i],u); double cur=1.0,w=1.05; int ans=0; while((int)cur<tid-lid[u]) cur*=w,ans++; tid=lid[u]+(int)cur; Code(u,(ll)ans*N+lid[u]); } void Encode(int n, int a[], int b[]) { for(int i=0;i<n-1;i++) AddEdge(a[i],b[i]); DFS(0,-1); }
#include "Device.h" const int N=250050*2; double ans[2050]; void InitDevice() { ans[0]=1.0; for(int i=1;i<2050;i++) ans[i]=ans[i-1]*1.05; } int Answer(long long S, long long T) { int x=S/N,l=S%N,r=l+(int)ans[x]-1; int y=T/N,L=T%N,R=L+(int)ans[y]-1; if(l<=L && R<=r) return 1; if(L<=l && r<=R) return 0; return 2; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...