結果
問題 | No.1364 [Renaming] Road to Cherry from Zelkova |
ユーザー | 37zigen |
提出日時 | 2021-01-21 23:41:28 |
言語 | Java21 (openjdk 21) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,693 bytes |
コンパイル時間 | 2,430 ms |
コンパイル使用メモリ | 78,852 KB |
実行使用メモリ | 81,724 KB |
最終ジャッジ日時 | 2024-06-07 12:04:13 |
合計ジャッジ時間 | 18,345 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 47 ms
41,720 KB |
testcase_01 | AC | 61 ms
38,112 KB |
testcase_02 | AC | 47 ms
36,796 KB |
testcase_03 | AC | 48 ms
36,796 KB |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | AC | 88 ms
40,880 KB |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | AC | 86 ms
40,176 KB |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | AC | 238 ms
59,256 KB |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | AC | 186 ms
52,424 KB |
testcase_24 | AC | 159 ms
46,736 KB |
testcase_25 | AC | 307 ms
67,576 KB |
testcase_26 | AC | 402 ms
77,236 KB |
testcase_27 | AC | 325 ms
64,652 KB |
testcase_28 | AC | 267 ms
62,696 KB |
testcase_29 | AC | 301 ms
64,332 KB |
testcase_30 | AC | 269 ms
62,952 KB |
testcase_31 | AC | 229 ms
59,072 KB |
testcase_32 | AC | 257 ms
58,676 KB |
testcase_33 | AC | 403 ms
76,492 KB |
testcase_34 | AC | 436 ms
76,716 KB |
testcase_35 | AC | 469 ms
81,724 KB |
testcase_36 | AC | 319 ms
71,928 KB |
testcase_37 | AC | 261 ms
58,784 KB |
testcase_38 | TLE | - |
testcase_39 | -- | - |
testcase_40 | -- | - |
testcase_41 | -- | - |
testcase_42 | -- | - |
testcase_43 | -- | - |
testcase_44 | -- | - |
testcase_45 | -- | - |
testcase_46 | -- | - |
testcase_47 | -- | - |
ソースコード
import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.Arrays; import java.util.NoSuchElementException; public class Main { public static void main(String[] args) { new Main().run(); } final long p=(long)1e9+7; class Edge { int src, dst; long dist, cnt; public Edge(int src, int dst, long dist, long cnt) { this.src = src; this.dst = dst; this.dist = dist; this.cnt = cnt; } } void run() { FastScanner sc=new FastScanner(); int N=sc.nextInt()+1; int M=sc.nextInt(); ArrayList<Edge>[] g=new ArrayList[N]; ArrayList<Edge>[] grev=new ArrayList[N]; for (int i=0;i<g.length;++i) g[i]=new ArrayList<>(); for (int i=0;i<g.length;++i) grev[i]=new ArrayList<>(); for (int i=0;i<M;++i) { int u=sc.nextInt(); int v=sc.nextInt(); int l=sc.nextInt(); int a=sc.nextInt(); g[u].add(new Edge(u, v, l, a)); grev[v].add(new Edge(v, u, l, a)); } long[] ans=new long[N]; long[] cnt=new long[N]; cnt[N-1]=1; int[] state=new int[N]; boolean[] a=new boolean[N]; boolean[] b=new boolean[N]; dfs0(0,g,a); dfs0(N-1,grev,b); for (int i=0;i<N;++i) a[i] &= b[i]; Arrays.fill(state, 0); dfs(0, g, ans, state, cnt, a); System.out.println(ans[0]); } void dfs0(int cur, ArrayList<Edge>[] g, boolean[] valid) { valid[cur]=true; for (Edge e:g[cur]) { if (!valid[e.dst]) dfs0(e.dst,g,valid); } } void dfs(int cur, ArrayList<Edge>[] g, long[] ans, int[] state, long[] cnt, boolean[] ok) { state[cur]=1; for (Edge e:g[cur]) if (ok[e.dst]) { if (state[e.dst]==1) { System.out.println("INF"); System.exit(0); } dfs(e.dst,g,ans,state,cnt,ok); } for (Edge e:g[cur]) if (ok[e.dst]){ cnt[cur]+=cnt[e.dst]*e.cnt%p; cnt[cur]%=p; ans[cur]+=ans[e.dst]*e.cnt+cnt[e.dst]*e.cnt%p*e.dist%p; ans[cur]%=p; } state[cur]=2; } void tr(Object...objects) { System.out.println(Arrays.deepToString(objects)); } } class FastScanner { private final InputStream in = System.in; private final byte[] buffer = new byte[1024]; private int ptr = 0; private int buflen = 0; private boolean hasNextByte() { if (ptr < buflen) { return true; } else { ptr = 0; try { buflen = in.read(buffer); } catch (IOException e) { e.printStackTrace(); } if (buflen <= 0) { return false; } } return true; } private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1; } private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126; } public boolean hasNext() { while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte(); } public String next() { if (!hasNext()) throw new NoSuchElementException(); StringBuilder sb = new StringBuilder(); int b = readByte(); while (isPrintableChar(b)) { sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } public long nextLong() { if (!hasNext()) throw new NoSuchElementException(); long n = 0; boolean minus = false; int b = readByte(); if (b == '-') { minus = true; b = readByte(); } if (b < '0' || '9' < b) { throw new NumberFormatException(); } while (true) { if ('0' <= b && b <= '9') { n *= 10; n += b - '0'; } else if (b == -1 || !isPrintableChar(b)) { return minus ? -n : n; } else { throw new NumberFormatException(); } b = readByte(); } } public int nextInt() { long nl = nextLong(); if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException(); return (int) nl; } public double nextDouble() { return Double.parseDouble(next()); } }