Skip to content

Commit

Permalink
19-yuyu0830
Browse files Browse the repository at this point in the history
19-yuyu0830
  • Loading branch information
yuyu0830 authored Jul 25, 2024
2 parents f87df67 + 57a410e commit afe59d1
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 8 deletions.
18 changes: 10 additions & 8 deletions yuyu0830/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +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) | - |
| 14μ°¨μ‹œ| 2024.07.02 | μœ„μƒμ •λ ¬ | [ACM Craft](https://www.acmicpc.net/problem/1005) | - |
| 15μ°¨μ‹œ| 2024.06.01 | κΈ°ν•˜ | [λ‹€κ°ν˜•μ˜ 면적](https://www.acmicpc.net/problem/2166) | - |
| 16μ°¨μ‹œ | 2024.06.04 | λ³„μžλ¦¬ λ§Œλ“€κΈ° | [λ³„μžλ¦¬ λ§Œλ“€κΈ°](https://www.acmicpc.net/problem/4386) | - |
| 18μ°¨μ‹œ | 2024.07.06 | 2048 (Easy) | [2048 (Easy)](https://www.acmicpc.net/problem/12100) | - |
| 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) | - |
---
55 changes: 55 additions & 0 deletions yuyu0830/μž¬κ·€/1949.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#include <iostream>
#include <vector>

#define fastio ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

#define NUM 10002

using namespace std;

// x : 이 λ…Έλ“œλ₯Ό μ„ νƒν•˜μ§€ μ•Šμ•˜μ„ λ•Œμ˜ μ΅œλŒ€κ°’
// y : 이 λ…Έλ“œλ₯Ό μ„ νƒν–ˆμ„ λ•Œμ˜ μ΅œλŒ€κ°’
struct node {
int x, y;
node(int X, int Y) : x(X), y(Y) {};
int m() { return max(x, y); }
};

bool visited[NUM] = {0, };
int arr[NUM] = {0, };
vector<int> v[NUM];

node f(int t) {
visited[t] = true;

node tmp(0, arr[t]);

// 이 λ…Έλ“œμ—μ„œ 갈 수 μžˆλŠ” 가지듀을 탐색
for (auto i : v[t]) {
// λ°©λ¬Έν•œ λ…Έλ“œλ©΄ 가지 μ•ŠλŠ”λ‹€
if (!visited[i]) {
node a = f(i);

tmp.x += a.m();
tmp.y += a.x;
}
}

return tmp;
}

int main() {
fastio

int n; cin >> n;
for (int i = 1; i <= n; i++)
cin >> arr[i];

for (int i = 0; i < n - 1; i++) {
int a, b; cin >> a >> b;
v[a].push_back(b);
v[b].push_back(a);
}

printf("%d\n", f(1).m());
}

0 comments on commit afe59d1

Please sign in to comment.