본문 바로가기

Algorithm8

[Python] 백준 1516번 - 게임 개발 문제백준 1516번최종 코드import sysfrom collections import dequeinput = sys.stdin.readlineN = int(input())times = [0] * (N + 1)degree = [0] * (N + 1)buildings = [[] for _ in range(N + 1)]result = [0] * (N + 1)for i in range(1, N + 1): line = list(map(int, input().split())) for j in range(len(line)): if line[j] == -1: break if j == 0: times[i] = line[j] .. 2024. 5. 8.
[Python] 백준 1976번 - 여행 가자(2) 문제백준 1976번최종 코드import sysinput = sys.stdin.readlinen = int(input())m = int(input())L = [i for i in range(n + 1)]def union(a, b): if L[a] != a: a = find(a) if L[b] != b: b = find(b) if a != b: L[b] = adef find(a): if L[a] == a: return a root = find(L[a]) L[a] = root return rootfor i in range(1, n + 1): temp = [0] + list(map(int, input().split()).. 2024. 5. 6.
[Python] 백준 1043번 - 거짓말 문제백준 1043번최종 코드import sysinput = sys.stdin.readlinen, m = map(int, input().split())truth = list(map(int, input().split()))people = [i for i in range(n + 1)]parties = []def union(a, b): if people[a] != a: a = find(a) if people[b] != b: b = find(b) if a != b: people[b] = adef find(a): if people[a] == a: return a root = find(people[a]) people[a] = root .. 2024. 5. 6.
[Python] 백준 1976번 - 여행 가자 문제백준 1976번최종 코드import sysfrom collections import dequeinput = sys.stdin.readlinen = int(input())m = int(input())cities = [[0] for _ in range(n + 1)]# 연결 여부 확인def check_path(start, end): if start == end: return True que = deque() que.append(start) visited = [False] * (n + 1) visited[start] = True while que: now = que.popleft() if cities[now][end] == 1: .. 2024. 4. 3.