結果

問題 No.1473 おでぶなおばけさん
コンテスト
ユーザー shin
提出日時 2026-06-27 14:14:22
言語 Java
(openjdk 25.0.2)
コンパイル:
javac -encoding UTF8 _filename_
実行:
java -ea -Xmx700m -Xss256M -DONLINE_JUDGE=true _class_
結果
MLE  
実行時間 -
コード長 1,736 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 4,175 ms
コンパイル使用メモリ 84,824 KB
実行使用メモリ 714,044 KB
最終ジャッジ日時 2026-06-27 14:14:49
合計ジャッジ時間 25,226 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other WA * 2 RE * 15 MLE * 30
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class No1473 {

	public static void main(String[] args) throws IOException {
		
		String[] strings = readStr();
		
		int n = Integer.parseInt(strings[0].split(" ")[0]);
		int m = Integer.parseInt(strings[1].split(" ")[1]);
		
		long[][] std = new long[n+1][m+1];
		int[][] sg = new int[n+1][2];
		int s = 0 , t = 0;
		long d = 0;

		
		for(int i = 1;i <= m;i++) {
			s = Integer.parseInt(strings[i].split(" ")[0]);
			t = Integer.parseInt(strings[i].split(" ")[1]);
			d = Long.parseLong((strings[i].split(" ")[2]));
			
			if(s > t) {
				int t2 = t;
				t = s;
				s = t2;
			}
			
			std[s][t] = Math.max(std[s][t], d);
			
			if(sg[s][0] > 0) {
				sg[s][0] = Math.min(sg[s][0], t);
			}else {
				sg[s][0] = t;
			}
			
			sg[s][1] = Math.max(sg[s][1], t);

		}
		
		
		long[][] ans = new long[n+1][2];
		ans[1][0] = (long)Math.pow(10, 9);
		
		for(int i = 1;i <= n;i++) {
			for(int j = sg[i][0];j <= sg[i][1];j++) {
				
				if(ans[i][0] == 0 ) {
					break;
				}
				
				if(std[i][j] > 0 ) {
				
					d = ans[j][0];
				
					ans[j][0] = Math.max(ans[j][0], Math.min(ans[i][0], std[i][j]));
					
				
					if(d != ans[j][0] ) {
						ans[j][1] = ans[i][1] + 1;
					}
				
				}
				
			}
		}
		
		System.out.println(ans[n][0] + " " + ans[n][1]);
	
		
	}
	
	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;

	}

}
0