-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into 19-yuyu0830
- Loading branch information
Showing
11 changed files
with
241 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#include <iostream> | ||
#include <vector> | ||
|
||
using namespace std; | ||
|
||
class Solution { | ||
public: | ||
int minOperations(vector<string>& logs) { | ||
int height; | ||
|
||
height = 0; | ||
|
||
for (auto str : logs) | ||
{ | ||
if (str[0] != '.') height++; | ||
else if (str == "../") height = (height ? height - 1 : 0); | ||
} | ||
|
||
return height; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
n = int(input()) | ||
m = list(map(int,input().split())) | ||
|
||
for i in range(1,n): | ||
m[i] = max(m[i], m[i]+m[i-1]) | ||
print(max(m)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import sys | ||
input = sys.stdin.readline | ||
|
||
n,m = map(int,input().split()) | ||
parent = [i for i in range(n+1)] | ||
|
||
def find(x): | ||
if x!=parent[x]: | ||
parent[x] = find(parent[x]) | ||
return parent[x] | ||
|
||
def union(x,y): | ||
x,y = find(x),find(y) | ||
if x<y: | ||
parent[x] = y | ||
else: | ||
parent[y] = x | ||
|
||
for i in range(m): | ||
a,b,c = list(map(int,input().split())) | ||
if not a: | ||
union(b,c) | ||
else: | ||
if find(b) == find(c): | ||
print("YES") | ||
else: | ||
print("NO") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import sys | ||
input = sys.stdin.readline | ||
|
||
def find(x): | ||
if x!=root[x]: | ||
root[x] = find(root[x]) | ||
return root[x] | ||
|
||
|
||
while True: | ||
V,E = map(int,input().split()) | ||
if V==0 and E==0: | ||
break | ||
root = [i for i in range(V+1)] | ||
edge = [] # κ°μ 리μ€νΈ | ||
for i in range(E): | ||
a,b,c = map(int,input().split()) | ||
edge.append((a,b,c)) | ||
|
||
# λΉμ©μ κΈ°μ€μΌλ‘ μ€λ¦μ°¨μ | ||
edge.sort(key=lambda x:x[2]) | ||
|
||
ans = 0 | ||
for a,b,c in edge: | ||
aRoot = find(a) | ||
bRoot = find(b) | ||
if aRoot != bRoot: | ||
if aRoot < bRoot: | ||
root[bRoot] = aRoot | ||
else: | ||
root[aRoot] = bRoot | ||
else: | ||
ans+=c | ||
|
||
print(ans) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import collections | ||
import sys | ||
from heapq import heappop, heappush | ||
|
||
input = sys.stdin.readline | ||
|
||
N,M,T = map(int,input().split()) | ||
graph = collections.defaultdict(list) | ||
answer = 0 | ||
conquer_cost = 0 | ||
|
||
for _ in range(M): | ||
a,b,c = map(int,input().split()) | ||
graph[a].append((b,c)) | ||
graph[b].append((a,c)) | ||
|
||
visited=[False for _ in range(N+1)] | ||
heap=[(0,1)] | ||
|
||
while heap: | ||
cost,node = heappop(heap) # νμμ μ΅μλΉμ© κ°μ κΊΌλ | ||
|
||
if not visited[node]: # ν΄λΉ λ Έλ λ°©λ¬Έλμ§ μμλ€λ©΄ λ°©λ¬Έμ²λ¦¬ | ||
visited[node]=True | ||
answer += (cost + conquer_cost) # answerμ νμ¬ κ°μ λΉμ©κ³Ό Tμ ν©μ λν΄μ€ | ||
|
||
if node!=1: # 첫 λ²μ§Έ λ Έλ μλλ©΄, μ 볡λΉμ© T μ¦κ° | ||
conquer_cost += T | ||
|
||
for next_node,next_cost in graph[node]: # λ€μ λ Έλ νμνμ¬ νμ λ£κΈ° | ||
if not visited[next_node]: | ||
heappush(heap,(next_cost,next_node)) | ||
|
||
|
||
print(answer) |
30 changes: 30 additions & 0 deletions
30
seongwon030/μ΅μμ€ν¨λνΈλ¦¬/μ΅μμ€ν¨λνΈλ¦¬.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import sys | ||
|
||
input = sys.stdin.readline | ||
|
||
V,E = map(int,input().split()) | ||
root = [i for i in range(V+1)] | ||
edge = [] # κ°μ 리μ€νΈ | ||
for i in range(E): | ||
edge.append(list(map(int,input().split()))) | ||
|
||
# λΉμ©μ κΈ°μ€μΌλ‘ μ€λ¦μ°¨μ | ||
edge.sort(key=lambda x:x[2]) | ||
|
||
def find(x): | ||
if x!=root[x]: | ||
root[x] = find(root[x]) | ||
return root[x] | ||
|
||
ans = 0 | ||
for a,b,c in edge: | ||
aRoot = find(a) | ||
bRoot = find(b) | ||
if aRoot != bRoot: | ||
if aRoot > bRoot: | ||
root[aRoot] = bRoot | ||
else: | ||
root[bRoot] = aRoot | ||
ans += c | ||
|
||
print(ans) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#include <iostream> | ||
#include <queue> | ||
|
||
#define fastio ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); | ||
|
||
using namespace std; | ||
|
||
int f() { | ||
int n, m, t; | ||
cin >> n >> m; | ||
|
||
deque<bool> visited(n + 1, 0); | ||
vector<int> arr(n + 1, 0), enter(n + 1, 0), rule[n + 1]; | ||
|
||
// 건물 μ§λ μλ | ||
for (int i = 1; i <= n; i++) | ||
cin >> arr[i]; | ||
|
||
// 건물 μμ | ||
for (int i = 0; i < m; i++) { | ||
int a, b; cin >> a >> b; | ||
rule[a].push_back(b); | ||
enter[b]++; | ||
} | ||
|
||
cin >> t; | ||
|
||
int ret = 0; | ||
|
||
vector<int> tmp[2]; | ||
bool e = false; | ||
|
||
// μνλ 건물 μ§μ μ μμ λκΉμ§ λ°λ³΅ | ||
while (true) { | ||
// ret μκ°μ μ§μ μ μλ κ±΄λ¬Όλ€ νμ λ° tmp νμ push | ||
// μνλ 건물μ μ§μ μ μμΌλ©΄ ν¨μ μ’ λ£ λ° κ° λ°ν | ||
for (int i = 1; i <= n; i++) { | ||
if (!enter[i] && !visited[i]) { | ||
if (i == t) return ret + arr[i]; | ||
|
||
visited[i] = true; | ||
tmp[e].push_back(i); | ||
} | ||
} | ||
|
||
int m = 99999999; | ||
|
||
// μ§κΈ μ§κ³ μλ 건물 + μ§μ μ μλ 건물 μ€ μκ° κ°μ₯ μ κ² λ¨μ κ° νμ | ||
for (int i : tmp[e]) { m = min(m, arr[i]); } | ||
|
||
// tmp νμ μλ λͺ¨λ κ±΄λ¬Όλ€ mλ§νΌ κ±΄μ€ μ§ν, μμ±λλ©΄ νμμ μ κ±° | ||
while (!tmp[e].empty()) { | ||
int a = tmp[e].back(); | ||
tmp[e].pop_back(); | ||
|
||
arr[a] -= m; | ||
|
||
if (arr[a]) { tmp[!e].push_back(a); } | ||
else { for (int i : rule[a]) { enter[i]--; } } | ||
} | ||
|
||
e = !e; | ||
ret += m; | ||
} | ||
} | ||
|
||
int main() { | ||
fastio | ||
|
||
int testCase; cin >> testCase; | ||
while (testCase--) | ||
printf("%d\n", f()); | ||
} |