QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#55026#3047. Wind of Changezzt1208RE 0ms0kbC++2.6kb2022-10-11 23:08:422022-10-11 23:08:42

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-10-11 23:08:42]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2022-10-11 23:08:42]
  • 提交

answer


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
inline int read()
{
    int x=0,f=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=(x<<1)+(x<<3)+(c^48);c=getchar();}
    return x*f;
}
const int N=1e5+10,M=2e5+10;
ll d[N],mn[N],Ans[N];
int n;
struct I_love_Diana{
    int head[N],ver[M],nxt[M],tot,edge[M],sz[N],rt,mx[N];
    bool vis[N],o;
    vector<pair<int,ll>> v[N];
    void init(int n)
    {
        for(int i=1;i<=n;i++)head[i]=0,mx[i]=0;tot=0;
        for(int i=1;i<=n;i++)v[i].clear(),sz[i]=1;
        o=0,rt=0;
    }
    void add(int x,int y,int z)
    {
        ver[++tot]=y,edge[tot]=z;
        nxt[tot]=head[x],head[x]=tot;
    }
    void getrt(int x,int fa,int cnt)
    {
        sz[x]=1,mx[x]=0;
        for(int i=head[x];i;i=nxt[i]){
            int y=ver[i];
            if(y==fa||vis[y])continue;
            getrt(y,x,cnt),sz[x]+=sz[y],mx[x]=max(mx[x],sz[y]);
        }
        mx[x]=max(mx[x],cnt-sz[x]);
        if(mx[x]<mx[rt])rt=x;
    }
    void dfs(int x,int fa,int rt)
    {
        if(o)v[rt].pb(mp(x,d[x]));
        else v[x].pb(mp(rt,d[x]));
        for(int i=head[x];i;i=nxt[i]){
            int y=ver[i],z=edge[i];
            if(y==fa||vis[y])continue;
            d[y]=d[x]+z,dfs(y,x,rt);
        }
    }
    void div(int x)
    {
        vis[x]=1,d[x]=0,dfs(x,0,x);
        for(int i=head[x];i;i=nxt[i]){
            int y=ver[i];
            if(vis[y])continue;
            rt=0,getrt(y,x,sz[y]),div(rt);
        }
    }
    void work(){mx[0]=0x3f3f3f3f,getrt(1,0,n),div(rt);}
}T1,T2;
//T1:后代   T2:祖先
void calc(int l1)
{
    vi zzt;
    for(auto it1:T1.v[l1]){
        int x=it1.fi;
        for(auto it2:T2.v[x]){
            int l2=it2.fi;ll d=it1.se+it2.se;
            if(~mn[l2])Ans[x]=min(Ans[x],mn[l2]+d),mn[l2]=min(mn[l2],d);
            else mn[l2]=d,zzt.pb(l2);
        }
    }
    for(auto x:zzt)mn[x]=-1;
}
int main()
{
    n=read();
    for(int i=1;i<n;i++){
        int u=read(),v=read(),w=read();
        T1.add(u,v,w),T1.add(v,u,w);
    }
    for(int i=1;i<n;i++){
        int u=read(),v=read(),w=read();
        T2.add(u,v,w),T2.add(v,u,w);
    }
    memset(mn,-1,sizeof(mn)),memset(Ans,0x3f,sizeof(Ans));
    T1.o=1,T1.work(),T2.work();
    for(int i=1;i<=n;i++)calc(i),reverse(T1.v[i].begin(),T1.v[i].end()),calc(i);
    for(int i=1;i<=n;i++)printf("%lld\n",Ans[i]);
    return 0;
}

詳細信息

Test #1:

score: 0
Runtime Error

input:

250000
137466 116241 624409157
188961 163586 148491970
13958 122239 46409636
186120 44010 919858866
72320 102560 92679302
158544 236582 882613876
22331 114267 646741536
210782 42861 679450428
56693 45397 898958944
71188 114724 904191407
15203 225401 210626781
31071 144225 278121829
110354 83972 4557...

output:


result: