結果

問題 No.1473 おでぶなおばけさん
コンテスト
ユーザー shin
提出日時 2026-06-27 21:32:42
言語 Java
(openjdk 25.0.2)
コンパイル:
javac -encoding UTF8 _filename_
実行:
java -ea -Xmx700m -Xss256M -DONLINE_JUDGE=true _class_
結果
WA  
実行時間 -
コード長 2,595 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 4,788 ms
コンパイル使用メモリ 86,508 KB
実行使用メモリ 67,636 KB
最終ジャッジ日時 2026-06-27 21:33:13
合計ジャッジ時間 28,571 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 WA * 1
other AC * 8 WA * 39
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Queue;

public class No1473 {
	
	public static int n;
	public static ArrayList<tdMap>[] tdLists;


	public static void main(String[] args) throws IOException {
		
		//未完成

		String[] readStrings = readStr();
		n = Integer.parseInt(readStrings[0].split(" ")[0]);
		int m = Integer.parseInt(readStrings[0].split(" ")[1]);
		
		tdLists = new ArrayList[m+1];
		tdMap tdMap0;
		int[] dlist = new int[m];
		
		int s , t , d;
		for(int i = 1;i <= m;i++) {
			s = Integer.parseInt(readStrings[i].split(" ")[0]);
			t = Integer.parseInt(readStrings[i].split(" ")[1]);
			d = Integer.parseInt(readStrings[i].split(" ")[2]);
			
			tdMap0 = new tdMap(t, d);
			
			if(tdLists[s] == null) {
				tdLists[s] = new ArrayList<No1473.tdMap>();  
			}
			tdLists[s].add(tdMap0);
			dlist[i-1] = d;
		}
		
		Arrays.sort(dlist);
		
		int a = 0 , b = dlist.length-1 , h = calchalf(a, b) , ans = 0;
		
		while(dlist[h] > 0) {
			
			if(h == dlist.length-1) {
				break;
			}
			ans = rootcount(dlist[h]);
			if(ans == 0) {
				dlist[h] = 0;
				b = h;
				h = calchalf(a, b);
			}else {
				if(dlist[h+1] == 0) {
					break;
				}
				a = h;
				h = calchalf(a, b);
			}
		}
		
		System.out.println(dlist[h] + " " + rootcount(dlist[h]));
		
	}
	
	public static int calchalf(int a , int b) {
		return (a+b)/2 + (a+b)%2;
	}
	
	public static int rootcount(int w) {
		
		int[] root = new int[n+1];
		Queue<Integer> queue = new ArrayDeque<Integer>();
		ArrayList<tdMap> arrayList;
		queue.add(1);
		int s = 0;
		
		
		while(!queue.isEmpty()) {
			s = queue.poll();
			arrayList = tdLists[s];
			
			if(arrayList == null) continue;
			
			for (tdMap tdMap : arrayList) {
				if(w <= tdMap.getd() && (root[tdMap.gett()] == 0 || root[tdMap.gett()] > root[s]+1)) {
					root[tdMap.gett()] = root[s] + 1;
					queue.add(tdMap.gett());
				}
			}
		}
		
		return root[n];
		
	}

	
	public static String[] readStr() throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		ArrayList<String> list = new ArrayList<>();

		do {
			list.add(br.readLine());
		}while(br.ready());

		br.close();

		String[] text = new String[list.size()];
		list.toArray(text);

		return text;

	}
	
	public static class tdMap{
		
		int t , d;
		
		public tdMap(int t , int d) {
			this.t = t;
			this.d = d;
		}
		
		public int getd() {
			return this.d;
		}
		public int gett() {
			return this.t;
		}
	}
	

}
0