# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
932483 | 2024-02-23T13:38:14 Z | ErJ | Cat Exercise (JOI23_ho_t4) | C++17 | 2000 ms | 26408 KB |
#include <bits/stdc++.h> using namespace std; #define ll long long #define vi vector<ll> #define vvi vector<vector<ll>> #define vs vector<string> #define vc vector<char> #define vb vector<bool> #define vp vector<pair<ll, ll>> #define pp pair<ll, ll> #define qi queue<ll> #define qp queue<pp> #define pqi priority_queue<ll> #define pqp priority_queue<pp> #define mi map<ll, ll> #define mpi map<pp, ll> #define mip map<ll, pp> #define mpp map<pp, pp> #define mb map<ll, bool> #define si set<ll> #define sp set<pp> #define mod 1000000007 #define rep(a, b) for(int a = 0; a < (b); a++) #define rep2(a, b) for(int a = 1; a < (b); a++) #define inf 100000000000000 vvi edges; vi height; vb kamen; pp findMAX(ll v) {//distance, vertex vp val; qp q; q.push({ v, 0 }); vb was(edges.size()); rep(i, was.size()) was[i] = false; while (!q.empty()) { ll u = q.front().first; ll du = q.front().second; val.push_back({ u, du }); q.pop(); was[u] = true; rep(i, edges[u].size()) { ll w = edges[u][i]; if (!(was[w] || kamen[w])) { was[w] = true; q.push({ w, du + 1 }); } } } ll MAX = -1, indx = -1; rep(i, val.size()) { if (height[val[i].first] > MAX) { MAX = height[val[i].first]; indx = i; } } return { val[indx].second + 1, val[indx].first}; } ll solve(ll ans, ll cat) { kamen[cat] = true; ll ANS = ans; rep(i, edges[cat].size()) { ll v = edges[cat][i]; if (kamen[v]) continue; pp next = findMAX(v); ANS = max(ANS, solve(ans + next.first, next.second)); } return ANS; } int main() { int n; cin >> n; height.resize(n); kamen.resize(n); ll cat = 0; rep(i, n) { cin >> height[i]; kamen[i] = false; if (height[i] == n) { cat = i; } } edges.resize(n); rep(i, n - 1) { int u, v; cin >> u >> v; u--; v--; edges[u].push_back(v); edges[v].push_back(u); } cout << solve(0, cat) << endl; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 504 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 1 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 1 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 0 ms | 348 KB | Output is correct |
8 | Correct | 0 ms | 440 KB | Output is correct |
9 | Correct | 0 ms | 348 KB | Output is correct |
10 | Correct | 1 ms | 348 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 504 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 1 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 1 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 0 ms | 348 KB | Output is correct |
8 | Correct | 0 ms | 440 KB | Output is correct |
9 | Correct | 0 ms | 348 KB | Output is correct |
10 | Correct | 1 ms | 348 KB | Output is correct |
11 | Correct | 2 ms | 348 KB | Output is correct |
12 | Correct | 1 ms | 348 KB | Output is correct |
13 | Correct | 2 ms | 348 KB | Output is correct |
14 | Correct | 1 ms | 348 KB | Output is correct |
15 | Correct | 1 ms | 348 KB | Output is correct |
16 | Correct | 1 ms | 348 KB | Output is correct |
17 | Correct | 1 ms | 344 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 504 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 1 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 1 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 0 ms | 348 KB | Output is correct |
8 | Correct | 0 ms | 440 KB | Output is correct |
9 | Correct | 0 ms | 348 KB | Output is correct |
10 | Correct | 1 ms | 348 KB | Output is correct |
11 | Correct | 2 ms | 348 KB | Output is correct |
12 | Correct | 1 ms | 348 KB | Output is correct |
13 | Correct | 2 ms | 348 KB | Output is correct |
14 | Correct | 1 ms | 348 KB | Output is correct |
15 | Correct | 1 ms | 348 KB | Output is correct |
16 | Correct | 1 ms | 348 KB | Output is correct |
17 | Correct | 1 ms | 344 KB | Output is correct |
18 | Correct | 317 ms | 2668 KB | Output is correct |
19 | Correct | 297 ms | 2684 KB | Output is correct |
20 | Correct | 289 ms | 1172 KB | Output is correct |
21 | Correct | 45 ms | 860 KB | Output is correct |
22 | Correct | 51 ms | 860 KB | Output is correct |
23 | Correct | 44 ms | 908 KB | Output is correct |
24 | Correct | 43 ms | 860 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 504 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 1 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 1 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 0 ms | 348 KB | Output is correct |
8 | Correct | 0 ms | 440 KB | Output is correct |
9 | Correct | 0 ms | 348 KB | Output is correct |
10 | Correct | 1 ms | 348 KB | Output is correct |
11 | Correct | 2 ms | 348 KB | Output is correct |
12 | Correct | 1 ms | 348 KB | Output is correct |
13 | Correct | 2 ms | 348 KB | Output is correct |
14 | Correct | 1 ms | 348 KB | Output is correct |
15 | Correct | 1 ms | 348 KB | Output is correct |
16 | Correct | 1 ms | 348 KB | Output is correct |
17 | Correct | 1 ms | 344 KB | Output is correct |
18 | Correct | 317 ms | 2668 KB | Output is correct |
19 | Correct | 297 ms | 2684 KB | Output is correct |
20 | Correct | 289 ms | 1172 KB | Output is correct |
21 | Correct | 45 ms | 860 KB | Output is correct |
22 | Correct | 51 ms | 860 KB | Output is correct |
23 | Correct | 44 ms | 908 KB | Output is correct |
24 | Correct | 43 ms | 860 KB | Output is correct |
25 | Correct | 0 ms | 348 KB | Output is correct |
26 | Correct | 222 ms | 1152 KB | Output is correct |
27 | Correct | 230 ms | 1148 KB | Output is correct |
28 | Correct | 224 ms | 1064 KB | Output is correct |
29 | Correct | 225 ms | 1404 KB | Output is correct |
30 | Correct | 52 ms | 960 KB | Output is correct |
31 | Correct | 63 ms | 1052 KB | Output is correct |
32 | Correct | 57 ms | 1056 KB | Output is correct |
33 | Correct | 59 ms | 1112 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 504 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 1 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 1 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 0 ms | 348 KB | Output is correct |
8 | Correct | 0 ms | 440 KB | Output is correct |
9 | Correct | 0 ms | 348 KB | Output is correct |
10 | Correct | 1 ms | 348 KB | Output is correct |
11 | Correct | 2 ms | 348 KB | Output is correct |
12 | Correct | 1 ms | 348 KB | Output is correct |
13 | Correct | 2 ms | 348 KB | Output is correct |
14 | Correct | 1 ms | 348 KB | Output is correct |
15 | Correct | 1 ms | 348 KB | Output is correct |
16 | Correct | 1 ms | 348 KB | Output is correct |
17 | Correct | 1 ms | 344 KB | Output is correct |
18 | Correct | 317 ms | 2668 KB | Output is correct |
19 | Correct | 297 ms | 2684 KB | Output is correct |
20 | Correct | 289 ms | 1172 KB | Output is correct |
21 | Correct | 45 ms | 860 KB | Output is correct |
22 | Correct | 51 ms | 860 KB | Output is correct |
23 | Correct | 44 ms | 908 KB | Output is correct |
24 | Correct | 43 ms | 860 KB | Output is correct |
25 | Execution timed out | 2064 ms | 24636 KB | Time limit exceeded |
26 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 344 KB | Output is correct |
2 | Correct | 1 ms | 348 KB | Output is correct |
3 | Execution timed out | 2086 ms | 26408 KB | Time limit exceeded |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 504 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 1 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 1 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 0 ms | 348 KB | Output is correct |
8 | Correct | 0 ms | 440 KB | Output is correct |
9 | Correct | 0 ms | 348 KB | Output is correct |
10 | Correct | 1 ms | 348 KB | Output is correct |
11 | Correct | 2 ms | 348 KB | Output is correct |
12 | Correct | 1 ms | 348 KB | Output is correct |
13 | Correct | 2 ms | 348 KB | Output is correct |
14 | Correct | 1 ms | 348 KB | Output is correct |
15 | Correct | 1 ms | 348 KB | Output is correct |
16 | Correct | 1 ms | 348 KB | Output is correct |
17 | Correct | 1 ms | 344 KB | Output is correct |
18 | Correct | 317 ms | 2668 KB | Output is correct |
19 | Correct | 297 ms | 2684 KB | Output is correct |
20 | Correct | 289 ms | 1172 KB | Output is correct |
21 | Correct | 45 ms | 860 KB | Output is correct |
22 | Correct | 51 ms | 860 KB | Output is correct |
23 | Correct | 44 ms | 908 KB | Output is correct |
24 | Correct | 43 ms | 860 KB | Output is correct |
25 | Correct | 0 ms | 348 KB | Output is correct |
26 | Correct | 222 ms | 1152 KB | Output is correct |
27 | Correct | 230 ms | 1148 KB | Output is correct |
28 | Correct | 224 ms | 1064 KB | Output is correct |
29 | Correct | 225 ms | 1404 KB | Output is correct |
30 | Correct | 52 ms | 960 KB | Output is correct |
31 | Correct | 63 ms | 1052 KB | Output is correct |
32 | Correct | 57 ms | 1056 KB | Output is correct |
33 | Correct | 59 ms | 1112 KB | Output is correct |
34 | Execution timed out | 2064 ms | 24636 KB | Time limit exceeded |
35 | Halted | 0 ms | 0 KB | - |