| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 537579 | tqbfjotld | Paths (RMI21_paths) | C++14 | 184 ms | 35916 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
int K;
map<int,int > memo[100005];
vector<pair<int,int> > adjl[100005];
int dfs(int node, int pa, bool ig){
if (memo[node].count(pa)) return memo[node][pa];
int ans = 0;
int ans2 = -999999999;
int from1 = node;
for (auto x : adjl[node]){
if (ig && x.first==pa) continue;
auto res = dfs(x.first,node,ig)+x.second;
if (res>=ans){
from1 = x.first;
ans2 = ans;
ans = res;
}
else if (res>=ans2){
ans2 = res;
}
}
if (ig){
return memo[node][pa] = ans;
}
for (auto x : adjl[node]){
if (x.first==from1) memo[node][x.first] = ans2;
else memo[node][x.first] = ans;
}
memo[node][0] = ans;
return memo[node][pa];
}
main(){
int n;
scanf("%lld%lld",&n,&K);
for (int x = 0; x<n-1; x++){
int a,b,c;
scanf("%lld%lld%lld",&a,&b,&c);
adjl[a].push_back({b,c});
adjl[b].push_back({a,c});
}
for (int x = 1; x<=n; x++){
auto res = dfs(x,0,x==1);
int ans = res;
printf("%lld\n",ans);
}
}
컴파일 시 표준 에러 (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... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
