結果
問題 | No.1502 Many Simple Additions |
ユーザー | mkawa2 |
提出日時 | 2024-01-02 02:09:16 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,772 bytes |
コンパイル時間 | 284 ms |
コンパイル使用メモリ | 82,504 KB |
実行使用メモリ | 116,588 KB |
最終ジャッジ日時 | 2024-09-27 17:38:29 |
合計ジャッジ時間 | 7,143 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 41 ms
55,488 KB |
testcase_01 | AC | 43 ms
55,156 KB |
testcase_02 | AC | 42 ms
55,012 KB |
testcase_03 | AC | 41 ms
56,316 KB |
testcase_04 | AC | 41 ms
56,308 KB |
testcase_05 | AC | 40 ms
55,300 KB |
testcase_06 | AC | 41 ms
54,664 KB |
testcase_07 | AC | 40 ms
55,200 KB |
testcase_08 | AC | 41 ms
55,828 KB |
testcase_09 | AC | 41 ms
54,732 KB |
testcase_10 | AC | 41 ms
55,344 KB |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | AC | 43 ms
54,860 KB |
testcase_15 | AC | 41 ms
54,872 KB |
testcase_16 | AC | 45 ms
55,416 KB |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | AC | 41 ms
55,488 KB |
testcase_25 | AC | 42 ms
55,412 KB |
testcase_26 | WA | - |
testcase_27 | AC | 262 ms
116,588 KB |
testcase_28 | AC | 275 ms
116,448 KB |
testcase_29 | AC | 64 ms
70,824 KB |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | WA | - |
testcase_35 | WA | - |
testcase_36 | WA | - |
testcase_37 | AC | 199 ms
110,676 KB |
testcase_38 | AC | 232 ms
112,204 KB |
testcase_39 | AC | 162 ms
95,868 KB |
testcase_40 | AC | 168 ms
91,072 KB |
testcase_41 | AC | 96 ms
79,448 KB |
testcase_42 | AC | 268 ms
108,016 KB |
testcase_43 | AC | 41 ms
54,548 KB |
ソースコード
import sys # sys.setrecursionlimit(1000005) # sys.set_int_max_str_digits(200005) int1 = lambda x: int(x)-1 pDB = lambda *x: print(*x, end="\n", file=sys.stderr) p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr) def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LI1(): return list(map(int1, sys.stdin.readline().split())) def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def SI(): return sys.stdin.readline().rstrip() # dij = [(0, 1), (-1, 0), (0, -1), (1, 0)] dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)] # inf = -1-(-1 << 31) inf = -1-(-1 << 62) md = 10**9+7 # md = 998244353 from collections import defaultdict n,m,k=LI() to=[[] for _ in range(n)] uv2z=defaultdict(int) for _ in range(m): u,v,z=LI() u,v=u-1,v-1 to[u].append(v) to[v].append(u) uv2z[u,v]=uv2z[v,u]=z def dfs(root=0): aa[root]=1 stack = [(u, root) for u in to[root]] lmin=rmin=inf lmax=rmax=-inf while stack: u, p = stack.pop() z = uv2z[u, p] if aa[u]: if aa[u]==aa[p]: # 2x=au(z-bu-bp) x2=aa[u]*(z-bb[u]-bb[p]) if x2 < 2 or x2 > k*2 or x2&1: print(0) exit() x=x2//2 if xx[root]==None: xx[root]=x elif xx[root]!=x: print(0) exit() elif bb[u]!=bb[p]: print(0) exit() else: parent[u]=p aa[u]=-aa[p] bb[u]=z-bb[p] if aa[u]==1: lmin,lmax=min(lmin,bb[u]),max(lmax,bb[u]) else: rmin, rmax = min(rmin, bb[u]), max(rmax, bb[u]) for v in to[u]: if aa[v]:continue stack.append((v,u)) # x+lmin>=1 # x>=1-lmin # -x+rmin>=1 # x<=rmin-1 # x+lmax<=k # x<=k-lmax # -x+rmax<=k # x>=rmax-k if xx[root]==None: mn=max(1-lmin,rmax-k,1) mx=min(rmin-1,k-lmax,k) a1=max(0,mx-mn+1) mn=max(1-lmin,rmax-k+1,1) mx=min(rmin-1,k-1-lmax,k-1) a2=max(0,mx-mn+1) return a1,a2 x=xx[root] if x+lmin<1 or -x+rmin<1: print(0) exit() a1=a2=0 if x+lmax<=k and -x+rmax<=k:a1=1 if x+lmax<k and -x+rmax<k:a2=1 return a1,a2 parent = [-1]*n aa=[0]*n bb=[0]*n xx=[None]*n s1=s2=1 for u in range(n): if aa[u]:continue a1,a2=dfs(u) s1*=a1 s2*=a2 s1%=md s2%=md # print(u,a1,a2,s1,s2) # print(aa) # print(bb) # print(xx) print((s1-s2)%md)