QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#108664 | #5017. 相等树链 | chenshi | Compile Error | / | / | C++ | 3.0kb | 2023-05-25 22:33:32 | 2023-05-25 22:33:34 |
Judging History
你现在查看的是最新测评结果
- [2023-08-10 23:21:45]
- System Update: QOJ starts to keep a history of the judgings of all the submissions.
- [2023-05-25 22:33:34]
- 评测
- 测评结果:Compile Error
- 用时:0ms
- 内存:0kb
- [2023-05-25 22:33:32]
- 提交
answer
#include<bits/stdc++.h>
using namespace std;
#define z unordered_map<unsigned long long,int>
const int o=4e5+10;
int n,G,s[o],hs[o],seq[o],cnt;long long ans;bool vis[o];unsigned long long w[o];
mt19937_64 rnd(time(0));z mp1,mp2,mp3;z::iterator iter;
struct Edge{int v,p;};
struct Tree{
int h[o],cnt,fa[o],d[o],lg[o],dfn[o],ed[o];pair<int,int> st[20][o];unsigned long long s[o];Edge e[o];
inline void ad(int U,int V){e[++cnt].v=V;e[cnt].p=h[U];h[U]=cnt;}
void dfs(int nw){
st[0][dfn[nw]=++cnt]=make_pair(d[nw]=d[fa[nw]]+1,nw);s[nw]=s[fa[nw]]+w[nw];
for(int i=h[nw];i;i=e[i].p) if(e[i].v^fa[nw]) st[0][++cnt]=make_pair(d[nw],nw),dfs(e[i].v);
ed[nw]=cnt;
}
inline int lca(int x,int y){
int l=min(dfn[x],dfn[y]),r=max(ed[x],ed[y]),t=lg[r-l+1];
return min(st[t][l],st[t][r-(1<<t)+1]).second;
}
inline int dis(int x,int y){return d[x]+d[y]-2*d[lca(x,y)];}
inline unsigned long long S(int x,int y){int t=lca(x,y);return s[x]+s[y]-s[t]-s[fa[t]];}
inline void init(){
for(int i=2;i<=n;++i) scanf("%d",&fa[i]),ad(fa[i],i),ad(i,fa[i]);
cnt=0;dfs(1);lg[0]=-1;
for(int i=1;i<=cnt;++i) lg[i]=lg[i>>1]+1;
for(int i=1;i<20;++i) for(int j=1;j+(1<<(i-1))<=cnt;++j) st[i][j]=min(st[i-1][j],st[i-1][j+(1<<(i-1))]);
}
}T1,T2;
struct Path{
int u,v,d;
inline Path ins(int t){
int d1=T2.dis(u,t),d2=T2.dis(v,t);Path res=*this;
if(d1>d2&&d1>d) res.v=t,res.d=d1;
else if(d2>d) res.u=t,res.d=d2;
return res;
}
};
void Dfs(int nw,int fa){
s[seq[++cnt]=nw]=1;hs[nw]=0;
for(int i=T1.h[nw];i;i=T1.e[i].p) if(T1.e[i].v-fa&&!vis[T1.e[i].v])
Dfs(T1.e[i].v,nw),s[nw]+=s[T1.e[i].v],hs[nw]=((s[hs[nw]]>s[T1.e[i].v])?hs[nw]:T1.e[i].v);
}
void ddfs(int nw,int fa,unsigned long long Sx,Path p){
++mp1[T2.S(p.u,p.v)-Sx];++mp2[Sx-w[G]];
if(p.u-G&&p.v-G) ++mp3[Sx-T2.S(p.u,G)],++mp3[Sx-T2.S(p.v,G)];
for(int i=T1.h[nw];i;i=T1.e[i].p)
if(T1.e[i].v-fa&&!vis[T1.e[i].v]) ddfs(T1.e[i].v,nw,Sx+w[T1.e[i].v],p.ins(T1.e[i].v));
}
inline int f(z&mp,unsigned long long Key){if((iter=mp.find(Key))==mp.end()) return 0;return (*iter).second;}
void dfs(int nw,int fa,unsigned long long Sy,Path p){
ans+=f(mp1,Sy-w[G])+f(mp2,T2.S(p.u,p.v)-Sy);
if(p.u-G&&p.v-G) ans+=f(mp3,T2.S(p.u,G)-Sy)+f(mp3,T2.S(p.v,G)-Sy);
for(int i=T1.h[nw];i;i=T1.e[i].p)
if(T1.e[i].v-fa&&!vis[T1.e[i].v]) dfs(T1.e[i].v,nw,Sy+w[T1.e[i].v],p.ins(T1.e[i].v));
}
void dvd(int nw){f
cnt=0;Dfs(nw,0);G=seq[1];
for(int i=2;i<=cnt;++i) if(max(s[hs[seq[i]]],s[nw]-s[seq[i]])<max(s[hs[G]],s[nw]-s[G])) G=seq[i];
vis[G]=1;mp1.clear();mp2.clear();mp3.clear();mp1[0]=mp2[0]=mp3[0]=1;
for(int i=T1.h[G];i;i=T1.e[i].p) if(!vis[T1.e[i].v])
dfs(T1.e[i].v,nw,w[G]+w[T1.e[i].v],(Path){G,T1.e[i].v,T2.dis(G,T1.e[i].v)}),
ddfs(T1.e[i].v,nw,w[G]+w[T1.e[i].v],(Path){G,T1.e[i].v,T2.dis(G,T1.e[i].v)});
for(int i=T1.h[G];i;i=T1.e[i].p) if(!vis[T1.e[i].v]) dvd(T1.e[i].v);
}
int main(){
scanf("%d",&n);ans=n;
for(int i=1;i<=n;++i) w[i]=rnd();
T1.init();T2.init();
dvd(1);
printf("%lld",ans);
return 0;
}
Details
answer.code: In function ‘void dvd(int)’: answer.code:56:19: error: expected ‘;’ before ‘cnt’ 56 | void dvd(int nw){f | ^ | ; 57 | cnt=0;Dfs(nw,0);G=seq[1]; | ~~~ answer.code: In function ‘int main()’: answer.code:66:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 66 | scanf("%d",&n);ans=n; | ~~~~~^~~~~~~~~ answer.code: In member function ‘void Tree::init()’: answer.code:23:44: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 23 | for(int i=2;i<=n;++i) scanf("%d",&fa[i]),ad(fa[i],i),ad(i,fa[i]); | ~~~~~^~~~~~~~~~~~~