Skip to content

Commit

Permalink
22.08.31
Browse files Browse the repository at this point in the history
  • Loading branch information
delena0702 authored Aug 31, 2022
1 parent a0dbcd6 commit 5af78f5
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 0 deletions.
13 changes: 13 additions & 0 deletions BAEKJOON/10799_쇠막대기.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import sys
def input(): return sys.stdin.readline().strip()

string = input()
stack, answer, pre = 0, 0, '_'
for ch in string:
if ch == '(':
stack = stack + 1
else:
stack = stack - 1
answer = answer + (stack if pre == '(' else 1)
pre = ch
print(answer)
13 changes: 13 additions & 0 deletions BAEKJOON/10819_차이를_최대로.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from itertools import permutations
import sys
def input(): return sys.stdin.readline().strip()

N = int(input())
data = list(map(int, input().split()))
answer = 0
for arr in permutations(data):
temp = 0
for i in range(N - 1):
temp = temp + abs(arr[i] - arr[i + 1])
answer = max(answer, temp)
print(answer)
30 changes: 30 additions & 0 deletions BAEKJOON/1197_최소_스패닝_트리.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from heapq import heappop, heappush
import sys
def input(): return sys.stdin.readline().strip()

V, E = map(int, input().split())

edges = [[] for _ in range(V)]
for _ in range(E):
a, b, c = map(int, input().split())
edges[a - 1].append((b - 1, c))
edges[b - 1].append((a - 1, c))

pq = [(0, 0)]
solved = [False] * (V + 1)
answer = 0
for _ in range(V):
while True:
weight, here = heappop(pq)
if not solved[here]:
break

solved[here] = True
answer = answer + weight

for there, w in edges[here]:
if solved[there]:
continue

heappush(pq, (w, there))
print(answer)
8 changes: 8 additions & 0 deletions BAEKJOON/2217_로프.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import sys
def input(): return sys.stdin.readline().strip()

N = int(input())
data = list(sorted([int(input()) for _ in range(N)], reverse=True))
for i in range(N):
data[i] = data[i] * (i + 1)
print(max(data))
15 changes: 15 additions & 0 deletions BAEKJOON/2252_줄_세우기.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from collections import defaultdict
from graphlib import TopologicalSorter
import sys
def input(): return sys.stdin.readline().strip()

N, M = map(int, input().split())

graph = defaultdict(set)
for i in range(1, N + 1):
graph[i]
for _ in range(M):
a, b = map(int, input().split())
graph[b].add(a)

print(*TopologicalSorter(graph).static_order())
32 changes: 32 additions & 0 deletions BAEKJOON/2644_촌수계산.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
from collections import deque
import sys
def input(): return sys.stdin.readline().strip()

N = int(input())
a, b = map(int, input().split())
M = int(input())

edges = [[] for _ in range(N + 1)]
for _ in range(M):
x, y = map(int, input().split())
edges[x].append(y)
edges[y].append(x)

queue = deque([(a, 0)])
visited = [False] * (N + 1)
visited[a] = True
while(queue):
here, cost = queue.popleft()

if here == b:
print(cost)
break

for there in edges[here]:
if visited[there]:
continue

visited[there] = True
queue.append((there, cost + 1))
else:
print(-1)

0 comments on commit 5af78f5

Please sign in to comment.