Submission #1962629


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;
    static boolean[] used;

    static boolean dfs(int s,int v,int c){
        used[s]=true;
        if(s==v)return true;
        for(Edge e : edgeList[s]){
            if(e.cost > c)continue;
            if(used[e.to])continue;
            if(dfs(e.to,v,c))return true;
        }
        return false;
    }

    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];
            }
        }

        used = new boolean[N];
        int left=0;
        int right = (int)1e9;
        while(right - left > 1){
            Arrays.fill(used, false);
            int center=(left+right)/2;
            if(dfs(src,dst,center)){
                right = center;
            }else{
                left = center;
            }
        }
        System.out.println(right);

        // 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 4822 Byte
Status WA
Exec Time 829 ms
Memory 84528 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 788 ms 78004 KB
large/20_large-01 WA 829 ms 78232 KB
large/20_large-02 AC 798 ms 82144 KB
large/20_large-03 WA 775 ms 80388 KB
large/20_large-04 WA 760 ms 84528 KB
large/31_max_large AC 509 ms 49828 KB
small/00_sample00 AC 175 ms 24016 KB
small/00_sample01 AC 177 ms 24148 KB
small/00_sample02 AC 171 ms 26064 KB
small/10_small-0000 WA 228 ms 24340 KB
small/10_small-0001 AC 224 ms 26996 KB
small/10_small-0002 AC 226 ms 26484 KB
small/10_small-0003 WA 221 ms 24688 KB
small/10_small-0004 AC 221 ms 26416 KB
small/10_small-0005 WA 219 ms 26656 KB
small/10_small-0006 AC 216 ms 26792 KB
small/10_small-0007 AC 229 ms 26300 KB
small/10_small-0008 AC 220 ms 28488 KB
small/10_small-0009 WA 226 ms 26916 KB
small/10_small-0010 AC 212 ms 25356 KB
small/10_small-0011 WA 217 ms 24244 KB
small/10_small-0012 WA 218 ms 26796 KB
small/10_small-0013 WA 218 ms 24940 KB
small/10_small-0014 AC 218 ms 24936 KB
small/10_small-0015 AC 224 ms 25000 KB
small/10_small-0016 WA 209 ms 27372 KB
small/10_small-0017 WA 226 ms 24652 KB
small/10_small-0018 AC 234 ms 24972 KB
small/10_small-0019 AC 236 ms 26536 KB
small/30_max_small AC 213 ms 26676 KB
small/40_simple_0000 AC 177 ms 24404 KB
small/40_simple_0001 AC 174 ms 26324 KB
small/40_simple_0002 AC 174 ms 24396 KB
small/40_simple_0003 AC 172 ms 23892 KB
small/40_simple_0004 AC 181 ms 25940 KB
small/40_simple_0005 AC 178 ms 26196 KB
small/40_simple_0006 AC 187 ms 26708 KB
small/40_simple_0007 AC 172 ms 24788 KB
small/40_simple_0008 AC 177 ms 22484 KB
small/40_simple_0009 AC 183 ms 24012 KB
small/40_simple_0010 AC 184 ms 24016 KB
small/40_simple_0011 AC 178 ms 25940 KB
small/40_simple_0012 AC 185 ms 24660 KB
small/40_simple_0013 AC 182 ms 25936 KB
small/40_simple_0014 AC 174 ms 25932 KB
small/40_simple_0015 AC 175 ms 24020 KB
small/40_simple_0016 AC 169 ms 24404 KB
small/40_simple_0017 AC 181 ms 26452 KB
small/40_simple_0018 AC 173 ms 27860 KB
small/40_simple_0019 AC 172 ms 26324 KB
small/90_dijkstra_killer_00 AC 174 ms 26324 KB
small/90_dijkstra_killer_01 AC 187 ms 24916 KB
small/91_tayama_killer_00 AC 176 ms 25936 KB
small/91_tayama_killer_01 AC 187 ms 24916 KB
small/91_tayama_killer_02 AC 183 ms 26452 KB
small/91_tayama_killer_03 AC 189 ms 24404 KB
small/91_tayama_killer_04 AC 180 ms 22740 KB
small/91_tayama_killer_05 AC 188 ms 26068 KB