Submission #1962393


Source Code Expand

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;

class Main{

    static class Dijkstra{
        class Edge{
            int to,cost;
            Edge(int t,int c){to=t;cost=c;}
        }

        int N;
        List<Edge>[] G;
        
        Dijkstra(int N){
            this.N=N;
            G = new ArrayList[N];
            for(int i=0;i<N;++i)G[i] = new ArrayList<>();
        }

        void addEdge(int from,int to,int cost){
            G[from].add(new Edge(to, cost));
        }

        int[] dijkstra(int s){
            class QueNode{
                int v,w;
                QueNode(int v,int w){this.v=v;this.w=w;}
            }
            int[] dis = new int[N];
            Arrays.fill(dis, Integer.MAX_VALUE);
            dis[s] = 0;
            PriorityQueue<QueNode> que = new PriorityQueue<>((a,b) -> a.w - b.w);
            que.add(new QueNode(s,0));
            while(!que.isEmpty()){
                QueNode node = que.poll();
                if(dis[node.v] < node.w)continue;
                for(Edge e : G[node.v]){
                    if(dis[e.to] > dis[node.v] + e.cost){
                        dis[e.to] = dis[node.v]+e.cost;
                        que.add(new QueNode(e.to, dis[e.to]));
                    }
                }
            }
            return dis;
        }
    }

    static class Edge{
        int cost;
        int sleepCost;
        int endPoint;
        int to;
        Edge(int end,int scost,int to){
            this.endPoint=end;
            this.sleepCost=scost;
            this.to=to;
        }
    }

    static List<Edge>[] edgeList;

    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        int M = scan.nextInt();
        int src=scan.nextInt();
        int dst=scan.nextInt();

        Dijkstra djk = new Dijkstra(N);
        edgeList = new ArrayList[N];
        for(int i=0;i<N;++i)edgeList[i] = new ArrayList<>();

        while(M-->0){
            int L = scan.nextInt();
            int[] s = new int[L];
            int[] w = new int[L-1];
            for(int i=0;i<L;++i)s[i] = scan.nextInt();
            for(int i=0;i<L-1;++i)w[i] = scan.nextInt();

            for(int i=0;i<L-1;++i){
                djk.addEdge(s[i], s[i+1], w[i]);
                djk.addEdge(s[i+1], s[i], w[i]);
            }

            int sleepcost=0;
            for(int i=0;i<L-1;++i)sleepcost += w[i];
            for(int i=0;i<L-1;++i){
                edgeList[s[i]].add(new Edge(s[L-1],sleepcost,s[i+1]));
                sleepcost -= w[i];
            }

            sleepcost=0;
            for(int i=0;i<L-1;++i)sleepcost += w[i];
            for(int i=L-1;i>0;--i){
                edgeList[s[i]].add(new Edge(s[0], sleepcost,s[i-1]));
                sleepcost -=w[i-1];
            }
        }
        int[] srcdis = djk.dijkstra(src);
        int[] dstdis = djk.dijkstra(dst);
        for(int i=0;i<N;++i){
            for(Edge e : edgeList[i]){
                e.cost = srcdis[i]+e.sleepCost + dstdis[e.endPoint];
            }
        }

        class QueNode{
            int v,w;
            QueNode(int v,int w){this.v=v;this.w=w;}
        }

        PriorityQueue<QueNode> que = new PriorityQueue<>((a,b) -> a.w-b.w);
        int[] dis = new int[N];
        Arrays.fill(dis, Integer.MAX_VALUE);
        dis[src] = 0;
        que.add(new QueNode(src, 0));
        while(!que.isEmpty()){
            QueNode node = que.poll();
            if(node.w > dis[node.v])continue;
            for(Edge e : edgeList[node.v]){
                int cost = Math.max(dis[node.v], e.cost);
                if(cost < dis[e.to]){
                    dis[e.to] = cost;
                    que.add(new QueNode(e.to, cost));
                }
            }
        }
        System.out.println(dis[dst]);
    }
}

Submission Info

Submission Time
Task C - メンテナンス明け
User inmir
Language Java8 (OpenJDK 1.8.0)
Score 0
Code Size 4053 Byte
Status WA
Exec Time 835 ms
Memory 80440 KB

Compile Error

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

Judge Result

Set Name Subtask1 Subtask2
Score / Max Score 0 / 50 0 / 50
Status
AC × 43
WA × 9
AC × 2
WA × 4
Set Name Test Cases
Subtask1 small/00_sample00, small/00_sample01, small/00_sample02, small/10_small-0000, small/10_small-0001, small/10_small-0002, small/10_small-0003, small/10_small-0004, small/10_small-0005, small/10_small-0006, small/10_small-0007, small/10_small-0008, small/10_small-0009, small/10_small-0010, small/10_small-0011, small/10_small-0012, small/10_small-0013, small/10_small-0014, small/10_small-0015, small/10_small-0016, small/10_small-0017, small/10_small-0018, small/10_small-0019, small/30_max_small, small/40_simple_0000, small/40_simple_0001, small/40_simple_0002, small/40_simple_0003, small/40_simple_0004, small/40_simple_0005, small/40_simple_0006, small/40_simple_0007, small/40_simple_0008, small/40_simple_0009, small/40_simple_0010, small/40_simple_0011, small/40_simple_0012, small/40_simple_0013, small/40_simple_0014, small/40_simple_0015, small/40_simple_0016, small/40_simple_0017, small/40_simple_0018, small/40_simple_0019, small/90_dijkstra_killer_00, small/90_dijkstra_killer_01, small/91_tayama_killer_00, small/91_tayama_killer_01, small/91_tayama_killer_02, small/91_tayama_killer_03, small/91_tayama_killer_04, small/91_tayama_killer_05
Subtask2 large/20_large-00, large/20_large-01, large/20_large-02, large/20_large-03, large/20_large-04, large/31_max_large
Case Name Status Exec Time Memory
large/20_large-00 WA 835 ms 80440 KB
large/20_large-01 WA 782 ms 71240 KB
large/20_large-02 AC 770 ms 72744 KB
large/20_large-03 WA 693 ms 71452 KB
large/20_large-04 WA 717 ms 70904 KB
large/31_max_large AC 492 ms 49244 KB
small/00_sample00 AC 184 ms 24016 KB
small/00_sample01 AC 184 ms 26056 KB
small/00_sample02 AC 178 ms 26452 KB
small/10_small-0000 WA 224 ms 27372 KB
small/10_small-0001 AC 216 ms 24880 KB
small/10_small-0002 AC 230 ms 24488 KB
small/10_small-0003 WA 232 ms 26440 KB
small/10_small-0004 AC 232 ms 25280 KB
small/10_small-0005 WA 219 ms 27316 KB
small/10_small-0006 AC 226 ms 26760 KB
small/10_small-0007 AC 215 ms 26772 KB
small/10_small-0008 AC 213 ms 26852 KB
small/10_small-0009 WA 224 ms 27216 KB
small/10_small-0010 AC 218 ms 24424 KB
small/10_small-0011 WA 236 ms 26436 KB
small/10_small-0012 WA 213 ms 24476 KB
small/10_small-0013 WA 219 ms 26152 KB
small/10_small-0014 AC 223 ms 26688 KB
small/10_small-0015 AC 234 ms 26612 KB
small/10_small-0016 WA 223 ms 26476 KB
small/10_small-0017 WA 223 ms 26608 KB
small/10_small-0018 AC 225 ms 26996 KB
small/10_small-0019 AC 216 ms 23752 KB
small/30_max_small AC 208 ms 26028 KB
small/40_simple_0000 AC 177 ms 26452 KB
small/40_simple_0001 AC 185 ms 26060 KB
small/40_simple_0002 AC 178 ms 24276 KB
small/40_simple_0003 AC 186 ms 24528 KB
small/40_simple_0004 AC 172 ms 26324 KB
small/40_simple_0005 AC 187 ms 26452 KB
small/40_simple_0006 AC 174 ms 26064 KB
small/40_simple_0007 AC 176 ms 26324 KB
small/40_simple_0008 AC 175 ms 26068 KB
small/40_simple_0009 AC 174 ms 25932 KB
small/40_simple_0010 AC 177 ms 26452 KB
small/40_simple_0011 AC 190 ms 24916 KB
small/40_simple_0012 AC 175 ms 26060 KB
small/40_simple_0013 AC 178 ms 26580 KB
small/40_simple_0014 AC 182 ms 26452 KB
small/40_simple_0015 AC 176 ms 24016 KB
small/40_simple_0016 AC 177 ms 24016 KB
small/40_simple_0017 AC 196 ms 28116 KB
small/40_simple_0018 AC 186 ms 26580 KB
small/40_simple_0019 AC 183 ms 26576 KB
small/90_dijkstra_killer_00 AC 179 ms 25940 KB
small/90_dijkstra_killer_01 AC 189 ms 25172 KB
small/91_tayama_killer_00 AC 185 ms 25044 KB
small/91_tayama_killer_01 AC 178 ms 26196 KB
small/91_tayama_killer_02 AC 183 ms 24272 KB
small/91_tayama_killer_03 AC 189 ms 26196 KB
small/91_tayama_killer_04 AC 186 ms 24276 KB
small/91_tayama_killer_05 AC 184 ms 26064 KB