zoukankan      html  css  js  c++  java
  • [codevs1947]道路修建 搜索、树p

    不明白为啥一定有一个点re,而同样的c++用int就能跑过(吃屎了有木有)

    此刻我内心是崩溃的= =

    而且在bz和code上,两个程序跑出来的结果也是不一样的,一个re一个a了

    先发一个95分的吧,到时候我再查一下

            var
                    pre,last,other,long:array[0..2002333] of qword;
                    k,l,n,tot,x,y,z:qword;
                    ans,d:qword;
                    i,j:longint;
    
                    procedure add(x,y,z:qword);
                    begin
                            inc(tot);
                            pre[tot]:=last[x];
                            last[x]:=tot;
                            other[tot]:=y;
                            long[tot]:=z;
                    end;
    
                    function dfs(x,p:qword):qword;
                    var t,i,v,size:qword;
                    begin
                            i:=1;
                            v:=1;
                            size:=1;
                            i:=last[x];
                            while i<>0 do
                            begin
                                    v:=other[i];
                                    if v=p then begin i:=pre[i]; continue; end;
                                    t:=dfs(v,x);
                                    inc(size,t);
                                    if n>2*t then d:=n-2*t else d:=2*t-n;
                                    inc(ans,d*long[i]);
                                    i:=pre[i];
                            end;
                            dfs:=size;
                    end;
    
                    begin
                            readln(j);
                            for i:=1 to j-1 do
                            begin
                                    readln(x,y,z);
                                    add(x,y,z);
                                    add(y,x,z);
                            end;
                            n:=j;
                            dfs(1,0);
                            writeln(ans);
                    end.
  • 相关阅读:
    CTreeCtrl::HitTest
    GetLastError()函数返回值及含义
    最大轮廓和投影 转
    一些Python黑客脚本
    win10系统架构调用
    rootkit基础
    面向对象编程
    机器学习概述
    XXE攻击
    浏览器安全
  • 原文地址:https://www.cnblogs.com/victorslave/p/4836652.html
Copyright © 2011-2022 走看看