結果
| 問題 |
No.1750 ラムドスウイルスの感染拡大-hard
|
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2021-11-22 10:21:25 |
| 言語 | Java (openjdk 23) |
| 結果 |
AC
|
| 実行時間 | 459 ms / 2,000 ms |
| コード長 | 2,433 bytes |
| コンパイル時間 | 2,450 ms |
| コンパイル使用メモリ | 78,900 KB |
| 実行使用メモリ | 48,156 KB |
| 最終ジャッジ日時 | 2024-06-23 20:10:24 |
| 合計ジャッジ時間 | 12,550 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 30 |
ソースコード
import java.io.*;
import java.util.*;
public class Main {
static final int MOD = 998244353;
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner();
int n = sc.nextInt();
int m = sc.nextInt();
long t = sc.nextLong();
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();
int b = sc.nextInt();
graph.get(a).add(b);
graph.get(b).add(a);
}
long[][][] matrixes = new long[63][n][n];
for (int i = 0; i < n; i++) {
for (int x : graph.get(i)) {
matrixes[0][i][x] = 1;
}
}
for (int i = 1; i < 63; i++) {
for (int a = 0; a < n; a++) {
for (int b = 0; b < n; b++) {
for (int c = 0; c < n; c++) {
matrixes[i][a][c] += matrixes[i - 1][a][b] * matrixes[i - 1][b][c] % MOD;
matrixes[i][a][c] %= MOD;
}
}
}
}
long[] ans = new long[n];
ans[0] = 1;
for (int i = 62; i >= 0 && t > 0; i--) {
if (t < (1L << i)) {
continue;
}
long[] next = new long[n];
t -= (1L << i);
for (int j = 0; j < n; j++) {
for (int k = 0; k < n; k++) {
next[j] += matrixes[i][j][k] * ans[k] % MOD;
next[j] %= MOD;
}
}
ans = next;
}
System.out.println(ans[0]);
}
}
class Scanner {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer("");
public Scanner() throws Exception {
}
public int nextInt() throws Exception {
return Integer.parseInt(next());
}
public long nextLong() throws Exception {
return Long.parseLong(next());
}
public double nextDouble() throws Exception {
return Double.parseDouble(next());
}
public String next() throws Exception {
if (!st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
return st.nextToken();
}
}
tenten