Submission #99873

#TimeUsernameProblemLanguageResultExecution timeMemory
99873TAISA_Snowy Roads (JOI16_snowy)C++14
55 / 100
46 ms2040 KiB
#include <bits/stdc++.h> #include "Anyalib.h" #define all(vec) vec.begin(),vec.end() #define mp make_pair using namespace std; using ll=long long; using P=pair<int,int>; const ll INF=1LL<<30; const ll LINF=1LL<<60; const double eps=1e-9; const ll MOD=1000000007LL; template<typename T>void chmin(T &a,T b){a=min(a,b);}; template<typename T>void chmax(T &a,T b){a=max(a,b);}; int dx[4]={0,1,0,-1}; int dy[4]={1,0,-1,0}; vector<vector<P>> G; vector<int> a,b; int id; int n; void InitAnya(int N,int A[],int B[]){ n=N; a.resize(N-1); b.resize(N-1); for(int i=0;i<N-1;i++){ a[i]=A[i]; b[i]=B[i]; } } void dfs(int i,int p,int sum,int dep){ if(dep%10==0){ for(int i=0;i<10;i++){ if(sum&(1<<i)){ Save(n+id*10+i,1); } } id++; } for(auto e:G[i]){ if(e.first==p)continue; Save(e.first,e.second); dfs(e.first,i,sum+e.second,dep+1); } } void Anya(int C[]){ G.clear(); G.resize(n); id=0; for(int i=0;i<n-1;i++){ G[a[i]].push_back(P(b[i],C[i])); G[b[i]].push_back(P(a[i],C[i])); } dfs(0,-1,0,0); }
#include <bits/stdc++.h> #include "Borislib.h" #define all(vec) vec.begin(),vec.end() #define mp make_pair using namespace std; using ll=long long; using P=pair<int,int>; const ll INF=1LL<<30; const ll LINF=1LL<<60; const double eps=1e-9; const ll MOD=1000000007LL; template<typename T>void chmin(T &a,T b){a=min(a,b);}; template<typename T>void chmax(T &a,T b){a=max(a,b);}; int dx[4]={0,1,0,-1}; int dy[4]={1,0,-1,0}; vector<vector<int>> G; vector<int> a,b,idx,par,d; int n,id; void dfs(int i,int p,int dep){ if(dep%10==0){ idx[i]=id; id++; } d[i]=dep; par[i]=p; for(auto e:G[i]){ if(e==p)continue; dfs(e,i,dep+1); } } void InitBoris(int N,int A[],int B[]){ n=N; a.resize(N-1); b.resize(N-1); idx.resize(n,-1); par.resize(n,-1); d.resize(n); G.resize(n); id=0; for(int i=0;i<N-1;i++){ a[i]=A[i]; b[i]=B[i]; G[a[i]].push_back(b[i]); G[b[i]].push_back(a[i]); } dfs(0,-1,0); } int Boris(int city){ int v=city; int res=0; while(1){ if(d[v]%10==0){ int k=idx[v]; for(int i=0;i<10;i++){ if(Ask(n+10*k+i)){ res+=(1<<i); } } break; }else{ res+=Ask(v); } v=par[v]; } return res; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...