Submission #2583276


Source Code Expand

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Scanner;

class Main{

    static class Edge{
        int[] v=new int[2];
        int[] cnt=new int[2];
        long w;
        Edge(int u1,int u2){v[0]=u1;v[1]=u2;}
    }

    static List<Edge> edges[];
    static boolean[] used;
    static int dfs(int v){
        used[v]=true;
        int res =1;
        for(Edge e : edges[v]){
            int i = e.v[0]==v ? 1:0;
            if(used[e.v[i]])continue;
            e.cnt[i]=dfs(e.v[i]);
            res += e.cnt[i];
        }
        return res;
    }

    static long dfs2(int v){
        used[v]=true;
        long res =0;
        for(Edge e: edges[v]){
            int i = e.v[0]==v ? 1:0;
            if(used[e.v[i]])continue;
            res += dfs2(e.v[i]);
            res += e.w*(long)e.cnt[i];
        }
        return res;
    }
    

    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        edges = new ArrayList[N];
        used = new boolean[N];
        List<Edge> edgeList = new ArrayList<>();
        for(int i=0;i<N;++i)edges[i]=new ArrayList<>();
        for(int i=0;i<N-1;++i){
            int a = scan.nextInt()-1;
            int b = scan.nextInt()-1;
            Edge e = new Edge(a, b);
            edgeList.add(e);
            edges[a].add(e);
            edges[b].add(e);
        }
        long[] s = new long[N];
        for(int i=0;i<N;++i)s[i]=scan.nextLong();
        dfs(0);
        for(Edge e: edgeList){
            if(e.cnt[0]==0)e.cnt[0]=N-e.cnt[1];
            else e.cnt[1]=N-e.cnt[0];
        }
        Edge equal=null;
        for(Edge e:edgeList){
            if(e.cnt[0]==e.cnt[1]){
                equal=e;
                e.w=0;
            }
            else e.w = ((s[e.v[0]] - s[e.v[1]])/((long)(e.cnt[1]-e.cnt[0])));
        }
        if(equal != null){
            equal.w = (s[equal.v[0]] - dfs2(equal.v[0])) / (equal.cnt[0]+1);
        }
        for(Edge e:edgeList)System.out.println(e.w);
    }
}

Submission Info

Submission Time
Task D - Ancient Tree Record
User inmir
Language Java8 (OpenJDK 1.8.0)
Score 200
Code Size 2144 Byte
Status WA
Exec Time 1527 ms
Memory 130832 KB

Compile Error

Note: ./Main.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

Judge Result

Set Name Sample Subtask1 Subtask2 All
Score / Max Score 0 / 0 0 / 300 200 / 200 0 / 300
Status
AC × 3
AC × 8
WA × 6
AC × 11
AC × 34
WA × 14
Set Name Test Cases
Sample 00_example_01.txt, 00_example_02.txt, 00_example_03.txt
Subtask1 00_example_01.txt, s1_01.txt, s1_02.txt, s1_03.txt, s1_04.txt, s1_05.txt, s1_06.txt, s1_07.txt, s1_08.txt, s1_09.txt, s1_10.txt, s1_11.txt, s1_12.txt, s1_13.txt
Subtask2 00_example_02.txt, s2_14.txt, s2_15.txt, s2_16.txt, s2_17.txt, s2_18.txt, s2_19.txt, s2_20.txt, s2_21.txt, s2_22.txt, s2_23.txt
All 00_example_01.txt, 00_example_02.txt, 00_example_03.txt, s1_01.txt, s1_02.txt, s1_03.txt, s1_04.txt, s1_05.txt, s1_06.txt, s1_07.txt, s1_08.txt, s1_09.txt, s1_10.txt, s1_11.txt, s1_12.txt, s1_13.txt, s2_14.txt, s2_15.txt, s2_16.txt, s2_17.txt, s2_18.txt, s2_19.txt, s2_20.txt, s2_21.txt, s2_22.txt, s2_23.txt, s3_24.txt, s3_25.txt, s3_26.txt, s3_27.txt, s3_28.txt, s3_29.txt, s3_30.txt, s3_31.txt, s3_32.txt, s3_33.txt, s3_34.txt, s3_35.txt, s3_36.txt, s3_37.txt, s3_38.txt, s3_39.txt, s3_40.txt, s3_41.txt, s3_42.txt, s3_43.txt, s3_44.txt, s3_45.txt
Case Name Status Exec Time Memory
00_example_01.txt AC 93 ms 20564 KB
00_example_02.txt AC 95 ms 21712 KB
00_example_03.txt AC 99 ms 21460 KB
s1_01.txt WA 989 ms 94820 KB
s1_02.txt AC 1280 ms 118548 KB
s1_03.txt WA 284 ms 35604 KB
s1_04.txt AC 1016 ms 107292 KB
s1_05.txt AC 446 ms 45900 KB
s1_06.txt AC 1448 ms 130240 KB
s1_07.txt WA 1417 ms 130832 KB
s1_08.txt AC 1376 ms 128708 KB
s1_09.txt WA 100 ms 19284 KB
s1_10.txt WA 100 ms 20948 KB
s1_11.txt AC 99 ms 19924 KB
s1_12.txt WA 99 ms 18772 KB
s1_13.txt AC 95 ms 18772 KB
s2_14.txt AC 1031 ms 94716 KB
s2_15.txt AC 1172 ms 106072 KB
s2_16.txt AC 1363 ms 120580 KB
s2_17.txt AC 1423 ms 122384 KB
s2_18.txt AC 1424 ms 122508 KB
s2_19.txt AC 1403 ms 119268 KB
s2_20.txt AC 99 ms 18644 KB
s2_21.txt AC 102 ms 19028 KB
s2_22.txt AC 100 ms 22740 KB
s2_23.txt AC 96 ms 19796 KB
s3_24.txt AC 1045 ms 93872 KB
s3_25.txt AC 1187 ms 107048 KB
s3_26.txt AC 293 ms 35368 KB
s3_27.txt AC 1069 ms 102804 KB
s3_28.txt AC 430 ms 43696 KB
s3_29.txt AC 1420 ms 118136 KB
s3_30.txt AC 1431 ms 120204 KB
s3_31.txt AC 1400 ms 119400 KB
s3_32.txt WA 1527 ms 123516 KB
s3_33.txt AC 1484 ms 130556 KB
s3_34.txt AC 1444 ms 122020 KB
s3_35.txt AC 1426 ms 119596 KB
s3_36.txt WA 93 ms 18640 KB
s3_37.txt AC 100 ms 18772 KB
s3_38.txt AC 114 ms 18900 KB
s3_39.txt AC 108 ms 19284 KB
s3_40.txt WA 941 ms 86740 KB
s3_41.txt WA 1197 ms 107052 KB
s3_42.txt WA 284 ms 36016 KB
s3_43.txt WA 1422 ms 117104 KB
s3_44.txt WA 1408 ms 119416 KB
s3_45.txt WA 1421 ms 121616 KB