# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
249378 | Sorting | Mousetrap (CEOI17_mousetrap) | C++14 | 374 ms | 76412 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int k_N = 1e6 + 3;
int n, t, m;
vector<int> adj[k_N];
pair<int, bool> dp[k_N];
int solve(int node, int p = -1){
if(node == t)
return -1;
auto &[ans, solved] = dp[node];
if(solved)
return ans;
solved = true;
ans = adj[node].size();
int max1 = 0, max2 = 0;
for(int to: adj[node]){
if(to == p)
continue;
int curr = solve(to, node);
if(curr >= max1){
max2 = max1;
max1 = curr;
}
else if(curr >= max2) max2 = curr;
}
ans += max2;
return ans;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> t >> m;
for(int i = 0; i < n - 1; ++i){
int u, v;
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
cout << solve(m) << "\n";
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |