https://www.acmicpc.net/problem/13168
ํ๋ก์ด๋ ๋ฌธ์ ๋ ํฐ์ด์ ๋นํด ์ฌ์ด ๋๋ใ
ใ
์ด ๋ฌธ์ ๋ ์ฒจ์ ์
๋ ฅ ๋ณด๊ณ ๊ฒฝ์
ํ์ง๋ง ํ๊ณ ๋ณด๋ ์ฌ์ด ๋ฌธ์ ์๋ค
import sys
INF = sys.maxsize
n, r = map(int, sys.stdin.readline().split())
city = {}
temp = list(sys.stdin.readline().split())
for i in range(n):
city[temp[i]] = i # ๋์
๋๋ฆฌ๋ฅผ ์ด์ฉํด 'city[๋์์ด๋ฆ] = ์ธ๋ฑ์ค'๋ก ์ ๋ฆฌํจ
m = int(sys.stdin.readline())
temp = list(sys.stdin.readline().split())
travel = []
for i in range(m):
travel.append(city[temp[i]]) # ์ฌํํ ๋์ ์ธ๋ฑ์ค ๋ฆฌ์คํธ๋ก ์ ์ฅํจ
k = int(input())
dist = [[INF] * n for _ in range(n)] # ๋ด์ผ๋ก๋ฅผ ์ฌ์ง ์์์ ๋ ์ต์ ๋น์ฉ
tomo = [[INF] * n for _ in range(n)] # ๋ด์ผ๋ก๋ฅผ ์์ ๋ ์ต์ ๋น์ฉ
for _ in range(k):
t, ss, es, c = input().split()
s, e = city[ss], city[es]
# ๋ด์ผ๋ก๋ฅผ ์ฌ์ง ์์์ ๋ ๋น์ฉ ์ ์ฅ
if dist[s][e] > int(c):
dist[s][e] = int(c)
dist[e][s] = int(c)
# ๋ด์ผ๋ก๋ฅผ ์์ ๋ ๋น์ฉ ์ ์ฅ
if t == 'Mugunghwa' or t == 'ITX-Saemaeul' or t == 'ITX-Cheongchun':
tomo[s][e] = 0
tomo[e][s] = 0
elif t == 'S-Train' or t == 'V-Train':
if tomo[s][e] > int(c) / 2:
tomo[s][e] = int(c) / 2
tomo[e][s] = int(c) / 2
else:
if tomo[s][e] > int(c):
tomo[s][e] = int(c)
tomo[e][s] = int(c)
# ํ๋ก์ด๋ ์๊ณ ๋ฆฌ์ฆ์ผ๋ก ์ต์ ๋น์ฉ ๊ตฌํ๊ธฐ
for l in range(n):
for i in range(n):
for j in range(n):
if dist[i][j] > dist[i][l] + dist[l][j]:
dist[i][j] = dist[i][l] + dist[l][j]
dist[j][i] = dist[j][l] + dist[l][i]
if tomo[i][j] > tomo[i][l] + tomo[l][j]:
tomo[i][j] = tomo[i][l] + tomo[l][j]
tomo[j][i] = tomo[j][l] + tomo[l][i]
# m๊ฐ์ ๋์๋ฅผ ์ฐจ๋ก๋๋ก ์ด๋ํ๋๋ฐ ๋๋ ๋น์ฉ ๊ณ์ฐ
yes, no = r, 0
for i in range(m-1):
s, e = travel[i], travel[i+1]
yes += tomo[s][e]
no += dist[s][e]
if yes >= no:
print('No')
else:
print('Yes')
ํท๊ฐ๋ ธ๋ ๋ถ๋ถ์ A ๋์์์ B ๋์๋ก ๊ฐ ๋ ๋๋ ๋น์ฉ๊ณผ B ๋์์์ A ๋์๋ก ์ฌ ๋ ๋๋ ๋น์ฉ์ด ๋์ผํ๋ค๋ ๊ฒ
๊ทธ๋ฆฌ๊ณ 50% ๋น์ฉ์ ๊ณ์ฐํ ๋ ์ ์ ๋๋๊ธฐ๋ก ํด์ฃผ๋ฉด ํ๋ฆฐ๋ค
100%์์ ํ๋ ค์ ์ง๋ฌธ ๊ฒ์ํ ๋ณด๊ณ ์์์