complete 30868.py and uncomplete 1717.py 1806.py 30869.py
This commit is contained in:
26
zeta_python/1717.py
Normal file
26
zeta_python/1717.py
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
import sys
|
||||||
|
|
||||||
|
input = sys.stdin.readline
|
||||||
|
|
||||||
|
|
||||||
|
def root(P, e):
|
||||||
|
node = e
|
||||||
|
while node != P[e]:
|
||||||
|
node = P[e]
|
||||||
|
return node
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
N, M = map(int, input().split())
|
||||||
|
P = [i for i in range(N + 1)]
|
||||||
|
for _ in range(M):
|
||||||
|
op, a, b = map(int, input().split())
|
||||||
|
if op == 0: # Merge
|
||||||
|
if a == b:
|
||||||
|
continue
|
||||||
|
rb, ra = root(P, b), root(P, a)
|
||||||
|
if rb != ra:
|
||||||
|
P[rb] = ra
|
||||||
|
print(P)
|
||||||
|
elif op == 1: # Find
|
||||||
|
print("YES" if a == b or root(P, a) == root(P, b) else "NO")
|
||||||
14
zeta_python/1806.py
Normal file
14
zeta_python/1806.py
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
def p_sum(cumulative, left, right):
|
||||||
|
if 0 <= left <= right <= N:
|
||||||
|
return cumulative[right] - cumulative[left]
|
||||||
|
else:
|
||||||
|
return 100000000000000000000000000
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
N, S = map(int, input().split())
|
||||||
|
A: list[int] = list(map(int, input().split()))
|
||||||
|
CA: list[int] = [0]
|
||||||
|
|
||||||
|
|
||||||
|
print(right - left)
|
||||||
40
zeta_python/30869.py
Normal file
40
zeta_python/30869.py
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
import sys
|
||||||
|
import heapq
|
||||||
|
|
||||||
|
input = sys.stdin.readline
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
N, M, K = map(int, input().split())
|
||||||
|
L = [[] for _ in range(M + 1)]
|
||||||
|
for _ in range(M):
|
||||||
|
s, e, t, g = map(int, input().split())
|
||||||
|
L[s].append((e, t, g))
|
||||||
|
res = 100000000000
|
||||||
|
|
||||||
|
D = []
|
||||||
|
vis_tmp = [0] * (N + 1)
|
||||||
|
vis_tmp[1] = 1
|
||||||
|
heapq.heappush(
|
||||||
|
D,
|
||||||
|
(0, 1, K, vis_tmp),
|
||||||
|
)
|
||||||
|
while D:
|
||||||
|
now_t, now_stop, now_k, vis = heapq.heappop(D)
|
||||||
|
vis[now_stop] = 1
|
||||||
|
if now_stop == N:
|
||||||
|
res = min(res, now_t)
|
||||||
|
break
|
||||||
|
|
||||||
|
for e, t, g in L[now_stop]:
|
||||||
|
if vis_tmp[e]:
|
||||||
|
continue
|
||||||
|
if now_t % g == 0:
|
||||||
|
heapq.heappush(D, (now_t + t, e, now_k, vis.copy()))
|
||||||
|
else:
|
||||||
|
heapq.heappush(D, (now_t + -now_t % g + g + t, e, now_k, vis.copy()))
|
||||||
|
# 버스 소환술 사용
|
||||||
|
if now_k >= 1:
|
||||||
|
heapq.heappush(D, (now_t + t, e, now_k - 1, vis.copy()))
|
||||||
|
else:
|
||||||
|
res = -1
|
||||||
|
print(res)
|
||||||
6
zeta_python/completed/30868.py
Normal file
6
zeta_python/completed/30868.py
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
if __name__ == "__main__":
|
||||||
|
T = int(input())
|
||||||
|
for i in range(T):
|
||||||
|
N = int(input())
|
||||||
|
d, r = divmod(N, 5)
|
||||||
|
print(" ".join(["++++"] * d) + ((" " if d else "") + "|" * r if r else ""))
|
||||||
Reference in New Issue
Block a user