結果

問題 No.1750 ラムドスウイルスの感染拡大-hard
ユーザー ks2mks2m
提出日時 2021-11-19 21:47:44
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,695 ms / 2,000 ms
コード長 1,385 bytes
コンパイル時間 4,663 ms
コンパイル使用メモリ 73,412 KB
実行使用メモリ 59,336 KB
最終ジャッジ日時 2023-08-30 08:04:06
合計ジャッジ時間 25,117 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
55,600 KB
testcase_01 AC 125 ms
56,240 KB
testcase_02 AC 125 ms
55,752 KB
testcase_03 AC 125 ms
55,868 KB
testcase_04 AC 253 ms
58,684 KB
testcase_05 AC 124 ms
56,012 KB
testcase_06 AC 123 ms
55,804 KB
testcase_07 AC 123 ms
55,596 KB
testcase_08 AC 390 ms
57,748 KB
testcase_09 AC 394 ms
58,464 KB
testcase_10 AC 395 ms
57,972 KB
testcase_11 AC 394 ms
59,096 KB
testcase_12 AC 480 ms
58,868 KB
testcase_13 AC 463 ms
58,636 KB
testcase_14 AC 1,640 ms
59,120 KB
testcase_15 AC 1,677 ms
58,660 KB
testcase_16 AC 1,695 ms
59,052 KB
testcase_17 AC 1,625 ms
58,372 KB
testcase_18 AC 1,675 ms
58,268 KB
testcase_19 AC 1,609 ms
58,568 KB
testcase_20 AC 1,170 ms
58,468 KB
testcase_21 AC 1,401 ms
58,724 KB
testcase_22 AC 415 ms
59,064 KB
testcase_23 AC 1,607 ms
58,792 KB
testcase_24 AC 322 ms
57,956 KB
testcase_25 AC 546 ms
58,508 KB
testcase_26 AC 279 ms
58,064 KB
testcase_27 AC 150 ms
55,656 KB
testcase_28 AC 156 ms
55,512 KB
testcase_29 AC 132 ms
54,188 KB
testcase_30 AC 415 ms
59,336 KB
testcase_31 AC 409 ms
58,876 KB
testcase_32 AC 403 ms
59,088 KB
testcase_33 AC 399 ms
59,052 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		long t = sc.nextLong();
		long[][] a = new long[n][n];
		for (int i = 0; i < m; i++) {
			int u = sc.nextInt();
			int v = sc.nextInt();
			a[u][v] = 1;
			a[v][u] = 1;
		}
		sc.close();

		int mod = 998244353;
		long[][] b = matrixPow(a, t, mod);
		long[] c = new long[n];
		c[0] = 1;
		long[] d = matrixMul1(c, b, mod);
		System.out.println(d[0]);
	}

	static long[][] matrixPow(long[][] a, long k, int m) {
		if (k == 1) {
			return a;
		}
		long[][] ret = matrixPow(a, k / 2, m);
		ret = matrixMul(ret, ret, m);
		if (k % 2 == 1) {
			ret = matrixMul(ret, a, m);
		}
		return ret;
	}

	static long[][] matrixMul(long[][] a, long[][] b, int m) {
		int h = a.length;
		int w = b[0].length;
		int n = a[0].length;
		long[][] c = new long[h][w];
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				for (int x = 0; x < n; x++) {
					c[i][j] += a[i][x] * b[x][j];
					c[i][j] %= m;
				}
			}
		}
		return c;
	}

	static long[] matrixMul1(long[] a, long[][] b, int m) {
		int w = b[0].length;
		int n = a.length;
		long[] c = new long[w];
		for (int j = 0; j < w; j++) {
			for (int x = 0; x < n; x++) {
				c[j] += a[x] * b[x][j];
				c[j] %= m;
			}
		}
		return c;
	}
}
0