結果
| 問題 | 
                            No.1190 Points
                             | 
                    
| コンテスト | |
| ユーザー | 
                             tenten
                         | 
                    
| 提出日時 | 2020-08-24 22:37:18 | 
| 言語 | Java  (openjdk 23)  | 
                    
| 結果 | 
                             
                                WA
                                 
                             
                            
                         | 
                    
| 実行時間 | - | 
| コード長 | 2,553 bytes | 
| コンパイル時間 | 2,575 ms | 
| コンパイル使用メモリ | 83,436 KB | 
| 実行使用メモリ | 91,500 KB | 
| 最終ジャッジ日時 | 2024-11-06 10:49:46 | 
| 合計ジャッジ時間 | 38,454 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 15 WA * 10 | 
ソースコード
import java.util.*;
public class Main {
    static final int MAX = Integer.MAX_VALUE / 10;
	public static void main (String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int n = sc.nextInt();
     	int m = sc.nextInt();
     	int pp = sc.nextInt();
    	int s = sc.nextInt() - 1;
     	int g = sc.nextInt() - 1;
      	ArrayList<ArrayList<Integer>> graph = new ArrayList<>();
      	for (int i = 0; i < n; i++) {
      	    graph.add(new ArrayList<>());
      	}
      	for (int i = 0; i < m; i++) {
      	    int a = sc.nextInt() - 1;
      	    int b = sc.nextInt() - 1;
      	    graph.get(a).add(b);
      	    graph.get(b).add(a);
      	}
      	int[][] costsS = new int[2][n];
      	int[][] costsG = new int[2][n];
      	Arrays.fill(costsS[0], MAX);
      	Arrays.fill(costsS[1], MAX);
      	Arrays.fill(costsG[0], MAX);
      	Arrays.fill(costsG[1], MAX);
      	PriorityQueue<Path> queue = new PriorityQueue<>();
      	queue.add(new Path(s, 0));
      	while (queue.size() > 0) {
      	    Path p = queue.poll();
      	    if (costsS[p.value % 2][p.idx] <= p.value) {
      	        continue;
      	    }
      	    costsS[p.value % 2][p.idx] = p.value;
      	    for (int x : graph.get(p.idx)) {
      	        queue.add(new Path(x, p.value + 1));
      	    }
      	}
      	queue.add(new Path(g, 0));
      	while (queue.size() > 0) {
      	    Path p = queue.poll();
      	    if (costsG[p.value % 2][p.idx] <= p.value) {
      	        continue;
      	    }
      	    costsG[p.value % 2][p.idx] = p.value;
      	    for (int x : graph.get(p.idx)) {
      	        queue.add(new Path(x, p.value + 1));
      	    }
      	}
      	ArrayList<Integer> ans = new ArrayList<>();
      	for (int i = 0; i < n; i++) {
      	    if (costsS[0][i] + costsG[pp % 2][i] <= pp || costsS[1][i] + costsG[(pp + 1) % 2][i] <= pp) {
      	        ans.add(i + 1);
      	    }
      	}
      	if (ans.size() == 0) {
      	    System.out.println(-1);
      	} else {
      	    StringBuilder sb = new StringBuilder();
      	    sb.append(ans.size()).append("\n");
      	    for (int x : ans) {
      	        sb.append(x).append("\n");
      	    }
      	    System.out.print(sb);
      	}
    }
    
    static class Path implements Comparable<Path> {
        int idx;
        int value;
        
        public Path(int idx, int value) {
            this.idx = idx;
            this.value = value;
        }
        
        public int compareTo(Path another) {
            return value - another.value;
        }
    }
}
            
            
            
        
            
tenten