1. Problem
2. My Solution
import sys
import copy
from collections import deque
sys.setrecursionlimit(10**8)
def dfs(v, visited):
visited[v] = True
print(v, end=" ")
for u in graph[v]:
if visited[u] == False:
dfs(u, visited)
def bfs(v, visited):
queue = deque()
queue.append(v)
visited[v] = True
while(queue):
v = queue.popleft()
print(v, end=" ")
for u in graph[v]:
if visited[u] == False:
queue.append(u)
visited[u] = True
n,m,start = map(int,sys.stdin.readline().rstrip().split())
graph = [[] for _ in range(n+1)]
visited = [False] * (n+1)
for _ in range(m):
a,b = map(int,sys.stdin.readline().rstrip().split())
graph[a].append(b)
graph[b].append(a)
for i in range(len(graph)):
graph[i].sort()
dfs(start, visited.copy())
print("")
bfs(start, visited.copy())
1. Problem
2. My Solution
from itertools import permutations
import sys
sys.setrecursionlimit(10**4)
k = int(sys.stdin.readline())
sign = sys.stdin.readline().rstrip().split()
seq = list(permutations(range(10),k+1))
for i in seq[::-1]:
flag = False
for j in range(k):
if eval(str(i[j]) + sign[j] + str(i[j+1])) == False:
flag = True
break
if flag == False:
print(*i,sep="")
break
for i in seq:
flag = False
for j in range(k):
if eval(str(i[j]) + sign[j] + str(i[j+1])) == False:
flag = True
break
if flag == False:
print(*i,sep="")
break
import sys
sys.setrecursionlimit(10**8)
def solution(level):
if level >= (k+1):
ans.append(res.copy())
else:
for i in nums:
if visited[i] == True:
continue
elif level > 0 and eval(str(res[level-1])+ sign[level-1] + str(i)) == False:
continue
else:
res[level] = i
visited[i] = True
solution(level+1)
visited[i] = False
k = int(sys.stdin.readline())
sign = sys.stdin.readline().rstrip().split()
nums = [0,1,2,3,4,5,6,7,8,9]
visited = [False] * 10
res = [0] * (k+1)
ans = []
solution(0)
print(*max(ans),sep="")
print(*min(ans),sep="")
import sys
sys.setrecursionlimit(10**8)
def check(a,b,op):
if op == ">":
return a > b
else:
return a < b
def solution(level):
if level >= (k+1):
ans.append(res.copy())
else:
for i in nums:
if visited[i] == True:
continue
elif level > 0 and check(res[level-1],i,sign[level-1]) == False:
continue
else:
res[level] = i
visited[i] = True
solution(level+1)
visited[i] = False
k = int(sys.stdin.readline())
sign = sys.stdin.readline().rstrip().split()
nums = [0,1,2,3,4,5,6,7,8,9]
visited = [False] * 10
res = [0] * (k+1)
ans = []
solution(0)
print(*max(ans),sep="")
print(*min(ans),sep="")
3. Learned
1. Problem
2. My Solution
import sys
n = int(sys.stdin.readline())
level = 0
level_max = 0
while(n > level_max):
level += 1
level_max += level
if level % 2 == 0:
top = level - (level_max - n)
bottom = level_max - n + 1
else:
top = level_max - n + 1
bottom = level - (level_max-n)
print(f"{top}/{bottom}")
3. Learned