Skip to content

Commit

Permalink
Merge branch 'main' into 19-yuyu0830
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyu0830 authored Jul 25, 2024
2 parents 637c42f + f87df67 commit 57a410e
Show file tree
Hide file tree
Showing 11 changed files with 241 additions and 7 deletions.
1 change: 1 addition & 0 deletions InSange/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@
| 15μ°¨μ‹œ | 2024.05.27 | μ •λ ¬ | [ν†΅λ‚˜λ¬΄ κ±΄λ„ˆλ›°κΈ°](https://www.acmicpc.net/problem/11497) | [#15](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/57)]
| 16μ°¨μ‹œ | 2024.06.28 | κ·Έλž˜ν”„ | [Maximum_Total_Importance_ofRoads](https://leetcode.com/problems/maximum-total-importance-of-roads/) | [#16](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/63)]
| 17μ°¨μ‹œ | 2024.06.28 | λ¬Έμžμ—΄ | [Zigzag Conversion](https://leetcode.com/problems/zigzag-conversion/) | [#17](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/64)]
| 18μ°¨μ‹œ | 2024.07.10 | λ¬Έμžμ—΄ | [Crawler Log Folder](https://leetcode.com/problems/crawler-log-folder/) | [#18](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/70)]
---
21 changes: 21 additions & 0 deletions InSange/λ¬Έμžμ—΄/1598_Crawler Log Folder.cpp
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;
}
};
6 changes: 6 additions & 0 deletions seongwon030/DP/연속합.py
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))
5 changes: 4 additions & 1 deletion seongwon030/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
| 10μ°¨μ‹œ | 2024.05.07 | μˆ˜ν•™ | [연속 ν•©](https://www.acmicpc.net/problem/2737) | [#10](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/43) |
| 11μ°¨μ‹œ | 2024.05.07 | DP | [ν•©λΆ„ν•΄](https://www.acmicpc.net/problem/2225) | [#11](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/44) |
| 12μ°¨μ‹œ | 2024.05.13 | 브루트포슀 | [μ•”ν˜Έλ§Œλ“€κΈ°](https://www.acmicpc.net/problem/1759) | [#12](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/50) |
| 13μ°¨μ‹œ | 2024.05.23 | 뢄할정볡 | [ν”Όλ³΄λ‚˜μΉ˜ 수 6](https://www.acmicpc.net/problem/11444) | [#13](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/54) |
| 13μ°¨μ‹œ | 2024.05.23 | 뢄할정볡 | [ν”Όλ³΄λ‚˜μΉ˜ 수 6](https://www.acmicpc.net/problem/11444) | [#13](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/55) |
| 14μ°¨μ‹œ | 2024.05.28 | 큐 | [κ°€μš΄λ°λ₯Ό λ§ν•΄μš”](https://www.acmicpc.net/problem/1655) | [#14](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/58) |
| 15μ°¨μ‹œ | 2024.06.01 | 큐 | [쀑앙값 κ΅¬ν•˜κΈ°](https://www.acmicpc.net/problem/2696) | [#15](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/61) |
| 16μ°¨μ‹œ | 2024.07.04 | DP | [연속합](https://www.acmicpc.net/problem/1912) | [#16](https://github.com/AlgoLeadMe/AlgoLeadMe-8/pull/66) |

---
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")
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)
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)
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)
15 changes: 9 additions & 6 deletions yuyu0830/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@
| 7μ°¨μ‹œ | 2024.04.04 | μ €μšΈ | [μ €μšΈ](https://www.acmicpc.net/problem/2437) | - |
| 8μ°¨μ‹œ | 2024.04.11 | 그리디 | [보석도둑](https://www.acmicpc.net/problem/1202) | - |
| 9μ°¨μ‹œ | 2024.04.12 | μ •λ ¬ | [μ•Œκ³ λ¦¬μ¦˜ μˆ˜μ—… - 버블 μ •λ ¬ 3](https://www.acmicpc.net/problem/23970) | - |
| 10μ°¨μ‹œ| 2024.04.29 | λ°±νŠΈλž˜ν‚Ή | [λΉ„μˆ](https://www.acmicpc.net/problem/1799) | - |
| 11μ°¨μ‹œ| 2024.05.08 | 그리디 | [μ—°λ£Œ μ±„μš°κΈ°](https://www.acmicpc.net/problem/1826) | - |
| 12μ°¨μ‹œ| 2024.05.13 | ν•΄μ‹œ | [두 λ°°μ—΄μ˜ ν•©](https://www.acmicpc.net/problem/2143) | - |
| 13μ°¨μ‹œ| 2024.05.21 | LIS | [κ°€μž₯ κΈ΄ μ¦κ°€ν•˜λŠ” λΆ€λΆ„ μˆ˜μ—΄ 2](https://www.acmicpc.net/problem/12015) | - |
| 15μ°¨μ‹œ| 2024.06.01 | κΈ°ν•˜ | [λ‹€κ°ν˜•μ˜ 면적](https://www.acmicpc.net/problem/2166) | - |
| 16μ°¨μ‹œ | 2024.06.04 | λ³„μžλ¦¬ λ§Œλ“€κΈ° | [λ³„μžλ¦¬ λ§Œλ“€κΈ°](https://www.acmicpc.net/problem/4386) | - |
| 10μ°¨μ‹œ | 2024.04.29 | λ°±νŠΈλž˜ν‚Ή | [λΉ„μˆ](https://www.acmicpc.net/problem/1799) | - |
| 11μ°¨μ‹œ | 2024.05.08 | 그리디 | [μ—°λ£Œ μ±„μš°κΈ°](https://www.acmicpc.net/problem/1826) | - |
| 12μ°¨μ‹œ | 2024.05.13 | ν•΄μ‹œ | [두 λ°°μ—΄μ˜ ν•©](https://www.acmicpc.net/problem/2143) | - |
| 13μ°¨μ‹œ | 2024.05.21 | LIS | [κ°€μž₯ κΈ΄ μ¦κ°€ν•˜λŠ” λΆ€λΆ„ μˆ˜μ—΄ 2](https://www.acmicpc.net/problem/12015) | - |
| 14μ°¨μ‹œ | 2024.05.30 | μˆ˜ν•™ | [μ„ λΆ„ ꡐ차](https://www.acmicpc.net/problem/17387) | - |
| 15μ°¨μ‹œ | 2024.06.01 | κΈ°ν•˜ | [λ‹€κ°ν˜•μ˜ 면적](https://www.acmicpc.net/problem/2166) | - |
| 16μ°¨μ‹œ | 2024.06.04 | MST | [λ³„μžλ¦¬ λ§Œλ“€κΈ°](https://www.acmicpc.net/problem/4386) | - |
| 17μ°¨μ‹œ | 2024.07.02 | μœ„μƒμ •λ ¬ | [ACM Craft](https://www.acmicpc.net/problem/1005) | - |
| 18μ°¨μ‹œ | 2024.07.06 | κ΅¬ν˜„ | [2048 (Easy)](https://www.acmicpc.net/problem/12100) | - |
| 19μ°¨μ‹œ | 2024.07.12 | μž¬κ·€ | [μš°μˆ˜λ§ˆμ„](https://www.acmicpc.net/problem/1949) | - |
---
Empty file added yuyu0830/κ΅¬ν˜„/12100.cpp
Empty file.
73 changes: 73 additions & 0 deletions yuyu0830/μœ„μƒμ •λ ¬/1005.cpp
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());
}

0 comments on commit 57a410e

Please sign in to comment.