結果

問題 No.1502 Many Simple Additions
ユーザー googol_S0googol_S0
提出日時 2021-05-07 22:02:15
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,658 bytes
コンパイル時間 267 ms
コンパイル使用メモリ 86,984 KB
実行使用メモリ 135,800 KB
最終ジャッジ日時 2023-10-13 13:05:13
合計ジャッジ時間 9,179 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 82 ms
71,264 KB
testcase_01 WA -
testcase_02 AC 81 ms
71,560 KB
testcase_03 AC 82 ms
71,560 KB
testcase_04 AC 83 ms
71,556 KB
testcase_05 WA -
testcase_06 AC 83 ms
71,680 KB
testcase_07 WA -
testcase_08 AC 76 ms
71,832 KB
testcase_09 AC 77 ms
71,400 KB
testcase_10 AC 78 ms
71,588 KB
testcase_11 WA -
testcase_12 AC 78 ms
71,564 KB
testcase_13 AC 78 ms
71,660 KB
testcase_14 AC 77 ms
71,588 KB
testcase_15 AC 78 ms
71,736 KB
testcase_16 AC 77 ms
71,672 KB
testcase_17 AC 78 ms
71,616 KB
testcase_18 AC 78 ms
71,692 KB
testcase_19 AC 78 ms
71,536 KB
testcase_20 AC 78 ms
71,564 KB
testcase_21 AC 79 ms
71,556 KB
testcase_22 AC 77 ms
71,540 KB
testcase_23 AC 78 ms
71,564 KB
testcase_24 AC 76 ms
71,428 KB
testcase_25 AC 77 ms
71,732 KB
testcase_26 AC 76 ms
71,600 KB
testcase_27 AC 213 ms
99,192 KB
testcase_28 AC 219 ms
99,732 KB
testcase_29 AC 145 ms
86,560 KB
testcase_30 AC 467 ms
135,800 KB
testcase_31 AC 468 ms
134,868 KB
testcase_32 AC 468 ms
128,152 KB
testcase_33 AC 330 ms
116,688 KB
testcase_34 AC 350 ms
120,760 KB
testcase_35 AC 309 ms
117,168 KB
testcase_36 WA -
testcase_37 AC 184 ms
112,632 KB
testcase_38 AC 290 ms
114,444 KB
testcase_39 AC 199 ms
103,096 KB
testcase_40 AC 216 ms
85,704 KB
testcase_41 AC 160 ms
82,012 KB
testcase_42 AC 396 ms
123,108 KB
testcase_43 AC 77 ms
71,724 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input=sys.stdin.buffer.readline
sys.setrecursionlimit(10**6)
N,M,K=map(int,input().split())
G=[[] for i in range(N)]
for i in range(M):
  x,y,z=map(int,input().split())
  x-=1
  y-=1
  G[x].append((y,z))
  G[y].append((x,z))
A=[]
ANS=1
ANS2=1
mod=10**9+7
F=[0]*N
X=[]
Y=[[] for i in range(N)]
V=K-1
from collections import *
INF=10**17
for i in range(N):
  if F[i]:
    continue
  for j in range(len(X)-1,-1,-1):
    Y[X[j]].clear()
    del X[j]
  Q=deque([(i,(1,0))])
  while len(Q):
    for _ in range(len(Q)):
      v=Q.popleft()
      X.append(v[0])
      F[v[0]]=1
      Y[v[0]].append(v[1])
      for j in range(len(G[v[0]])-1,-1,-1):
        Q.append((G[v[0]][j][0],(-v[1][0],G[v[0]][j][1]-v[1][1])))
        del G[v[0]][j]
  X=list(set(X))
  L,R=1,K
  L2,R2=1,V
  for j in range(len(X)):
    j=X[j]
    Z=[INF,INF]
    for k in range(len(Y[j])):
      if Y[j][k][0]==1:
        if Z[0]==INF:
          Z[0]=Y[j][k][1]
        else:
          if Z[0]!=Y[j][k][1]:
            L=K+1
            L2=K
      else:
        if Z[1]==INF:
          Z[1]=Y[j][k][1]
        else:
          if Z[1]!=Y[j][k][1]:
            L=K+1
            L2=K
    if Z[0]<INF and Z[1]<INF:
      if (Z[0]^Z[1])&1:
        L=K+1
        L2=K
      else:
        x=(Z[1]-Z[0])>>1
        L=max(L,x)
        L2=max(L2,x)
        R=min(R,x)
        R2=min(R2,x)
    elif Z[0]<INF:
      R=min(R,K-Z[0])
      R2=min(R2,V-Z[0])
      L=max(L,-Z[0]+1)
      L2=max(L2,-Z[0]+1)
    elif Z[1]<INF:
      R=min(R,Z[1]-1)
      R2=min(R2,Z[1]-1)
      L=max(L,Z[1]-K)
      L2=max(L2,Z[1]-V)
  ANS=ANS*max(0,R-L+1)%mod
  ANS2=ANS2*max(0,R2-L2+1)%mod
print((ANS-ANS2)%mod)
0