Submission #8347512
Source Code Expand
from heapq import heappop, heappush
MOD = 10**9+7
N,M= map(int,input().split(' '))
S,T= map(int,input().split(' '))
from collections import defaultdict
g = defaultdict(list)
for i in [0]*M:
u,v,d = list(map(int,input().split(' ')))
g[u].append((v,d))
g[v].append((u,d))
def dj(graph,s):
inf = 10**20
d = [inf]*(N+1)
d[s] = 0
num = [0]*(N+1)
num[s] = 1
que = []
heappush(que,(s,0))
while que:
s,dist = heappop(que)
if d[s] < dist:
continue
for t,c in g[s]:
if d[t] > d[s] + c:
d[t] = d[s] + c
num[t] = num[s]
heappush(que,(t,d[t]))
elif d[t] == d[s] + c:
num[t] += num[s]
num[t] = num[t] % MOD
return d,num
Sd,Snum = dj(g,S)
Td,Tnum = dj(g,T)
ans = Snum[T] * Tnum[S]
for v in range(1,N+1):
if Sd[v] == Td[v]:
ans -= Snum[v] * Tnum[v] * Snum[v] * Tnum[v]
for t, c in g[v]:
# S->v->t->T
if Sd[t] == Sd[v] + c and Td[v] == Td[t] + c:
if abs(Sd[v] - Td[t]) < c:
ans -= Snum[v] * Tnum[t] * Tnum[t] * Snum[v]
print(ans)
Submission Info
Submission Time |
|
Task |
E - Avoiding Collision |
User |
arfz |
Language |
Python (3.4.3) |
Score |
0 |
Code Size |
1216 Byte |
Status |
WA |
Exec Time |
2111 ms |
Memory |
127556 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
0 / 700 |
Status |
|
|
Set Name |
Test Cases |
Sample |
sample01.txt, sample02.txt, sample03.txt, sample04.txt |
All |
01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, sample01.txt, sample02.txt, sample03.txt, sample04.txt |
Case Name |
Status |
Exec Time |
Memory |
01.txt |
TLE |
2108 ms |
87756 KB |
02.txt |
TLE |
2110 ms |
112548 KB |
03.txt |
TLE |
2110 ms |
114352 KB |
04.txt |
TLE |
2111 ms |
116912 KB |
05.txt |
TLE |
2110 ms |
103504 KB |
06.txt |
TLE |
2109 ms |
91568 KB |
07.txt |
TLE |
2110 ms |
109360 KB |
08.txt |
WA |
1069 ms |
56244 KB |
09.txt |
TLE |
2110 ms |
112232 KB |
10.txt |
TLE |
2111 ms |
117500 KB |
11.txt |
TLE |
2110 ms |
112152 KB |
12.txt |
TLE |
2111 ms |
114672 KB |
13.txt |
TLE |
2110 ms |
109088 KB |
14.txt |
TLE |
2109 ms |
105492 KB |
15.txt |
TLE |
2110 ms |
114288 KB |
16.txt |
TLE |
2111 ms |
120376 KB |
17.txt |
TLE |
2111 ms |
127556 KB |
18.txt |
TLE |
2111 ms |
121944 KB |
sample01.txt |
AC |
20 ms |
3316 KB |
sample02.txt |
AC |
20 ms |
3316 KB |
sample03.txt |
AC |
20 ms |
3316 KB |
sample04.txt |
AC |
20 ms |
3316 KB |