반응형
import sys
sys.setrecursionlimit(10**9)
sys.stdin = open("input.txt")

input = sys.stdin.readline


n, m, r = map(int, input().split())

node = [[]for _ in range(n+1)]

for i in range(m):
    u, v = map(int, input().split())
    node[u].append(v)
    node[v].append(u)

for j in range(n+1):
    node[j].sort()

def dfs(v):
    global cnt
    visited[v] = cnt
    for i in node[v]:
        if not visited[i]:
            cnt+=1
            dfs(i)

cnt = 1

visited = [0] * (n + 1)
dfs(r)

for _ in range(1, n+1):
    print(visited[_])
반응형
반응형
n, m, v = map(int, input().split())
node = [[] for _ in range(n+1)]

for i in range(m):
    a, b = map(int, input().split())
    node[a].append(b)
    node[b].append(a)

for j in range(n+1):
    node[j].sort()

def dfs(v):
    visited1[v] = True
    print(v, end=' ')
    for i in node[v]:
        if not visited1[i]:
            dfs(i)


visited1 = [False] * (n+1)
dfs(v)

print()



from collections import deque

def bfs(v):
    queue = deque()
    queue.append(v)
    visited[v] = True

    while queue:
        v = queue.popleft()
        print(v, end= ' ')
        for i in node[v]:
            if not visited[i]:
                queue.append(i)
                visited[i] = True

visited = [False] * (n+1)
bfs(v)
반응형
반응형
n = int(input())
cnt = 0

while n >= 0:
    if n % 5 == 0:
        cnt += n // 5
        break
    else:
        n -= 3
        cnt += 1
else:
    cnt = -1

print(cnt)
반응형
반응형

📂 백준 7568 파이썬 (덩치)

www.acmicpc.net/problem/7568

n = int(input())
body = []

for _ in range(n):
    x, y = map(int, input().split())
    body.append([x, y])

score = [0]*len(body)


for i in range(len(body)):
    for j in range(len(body)):
        if body[i][0] > body[j][0] and body[i][1] > body[j][1]:
            score[j] += 1

for x in score:
    print(x+1, end=' ')
반응형

+ Recent posts