| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 491458 | blue | Harbingers (CEOI09_harbingers) | C++17 | 1092 ms | 19036 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
using namespace std;
using vi = vector<int>;
using ll = long long;
using vll = vector<ll>;
#define pb push_back
const int maxN = 100'000;
ll INF = 2'000'000'001;
vector<pair<int, ll>> edge[1+maxN];
vll S(1+maxN), V(1+maxN);
vi P(1+maxN);
vll D(1+maxN, 0);
vi ord;
void dfs(int u, int p)
{
ord.push_back(u);
P[u] = p;
for(auto x: edge[u])
{
int v = x.first;
ll d = x.second;
if(v == p) continue;
D[v] = D[u] + d;
dfs(v, u);
}
}
int main()
{
int N;
cin >> N;
for(int i = 1; i <= N-1; i++)
{
int u, v;
ll d;
cin >> u >> v >> d;
edge[u].pb({v, d});
edge[v].pb({u, d});
}
for(int i = 2; i <= N; i++) cin >> S[i] >> V[i];
dfs(1, 1);
vll dp(1+N, INF);
dp[1] = 0;
for(int u: ord)
{
for(int v = P[u]; 1; v = P[v])
{
dp[u] = min(dp[u], S[u] + V[u]*D[u] + (-D[v] * V[u] + dp[v]));
if(v == 1) break;
}
}
for(int i = 2; i <= N; i++) cout << dp[i] << ' ';
cout << '\n';
}
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
