aloha graph2(1967, 3109)
This commit is contained in:
40
zeta_python/completed/1967.py
Normal file
40
zeta_python/completed/1967.py
Normal file
@@ -0,0 +1,40 @@
|
||||
def solve(N, E):
|
||||
D = []
|
||||
D.append((0, 1, 0))
|
||||
finals = []
|
||||
while D:
|
||||
before, header, distance = D.pop(0)
|
||||
nexts = E[header]
|
||||
cnt = 0
|
||||
for s in nexts:
|
||||
if s[0] != before:
|
||||
D.append((header, s[0], distance + s[1]))
|
||||
cnt += 1
|
||||
if cnt == 0:
|
||||
finals.append((header, distance))
|
||||
|
||||
D = []
|
||||
s1 = max(finals, key=lambda x: x[1])
|
||||
D.append((0, s1[0], 0))
|
||||
finals = []
|
||||
while D:
|
||||
before, header, distance = D.pop(0)
|
||||
nexts = E[header]
|
||||
cnt = 0
|
||||
for s in nexts:
|
||||
if s[0] != before:
|
||||
D.append((header, s[0], distance + s[1]))
|
||||
cnt += 1
|
||||
if cnt == 0:
|
||||
finals.append((header, distance))
|
||||
|
||||
return max(finals, key=lambda x: x[1])[1]
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
N: int = int(input())
|
||||
E = [[] for _ in range(N + 1)]
|
||||
for a, b, v in [map(int, input().split()) for _ in range(N - 1)]:
|
||||
E[a].append((b, v))
|
||||
E[b].append((a, v))
|
||||
print(solve(N, E))
|
||||
45
zeta_python/completed/3109.py
Normal file
45
zeta_python/completed/3109.py
Normal file
@@ -0,0 +1,45 @@
|
||||
def get_maximum_upper(R, C, M, start):
|
||||
now_r = start
|
||||
now_c = 0
|
||||
D = [(now_r, now_c)]
|
||||
dir = [(-1, 1), (0, 1), (1, 1)]
|
||||
while D:
|
||||
now_r, now_c = D.pop()
|
||||
M[now_r][now_c] = 1
|
||||
insert = []
|
||||
for dr, dc in dir:
|
||||
new_r, new_c = now_r + dr, now_c + dc
|
||||
if new_c == C - 1:
|
||||
if 0 <= new_r < R:
|
||||
M[new_r][new_c] = 1
|
||||
return True
|
||||
continue
|
||||
|
||||
if 0 <= new_r < R:
|
||||
if M[new_r][new_c]:
|
||||
continue
|
||||
insert.append((new_r, new_c))
|
||||
if insert:
|
||||
D.extend(insert[::-1])
|
||||
return []
|
||||
|
||||
|
||||
def solve(R, C, M):
|
||||
cnt = 0
|
||||
for i in range(R):
|
||||
path = get_maximum_upper(R, C, M, i)
|
||||
if path:
|
||||
cnt += 1
|
||||
else:
|
||||
continue
|
||||
|
||||
return cnt
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
import sys
|
||||
|
||||
R, C = map(int, sys.stdin.readline().split())
|
||||
M = [list(map(lambda x: 1 if x == "x" else 0, sys.stdin.readline().rstrip())) for _ in range(R)]
|
||||
|
||||
print(solve(R, C, M))
|
||||
5
zeta_python/run.ps1
Normal file
5
zeta_python/run.ps1
Normal file
@@ -0,0 +1,5 @@
|
||||
if ($args.Length -gt 0) {
|
||||
type stdin.txt | python $args[0]
|
||||
} else {
|
||||
Write-Host "No args"
|
||||
}
|
||||
Reference in New Issue
Block a user