| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 | 
|---|---|---|---|---|---|---|---|
| 752646 | Tob | Harbingers (CEOI09_harbingers) | C++14 | 1082 ms | 65536 KiB | 
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair <ll, ll> pii;
typedef pair <pii, ll> piii;
const int N = 1e5 + 7;
int n;
ll a[N], b[N], dp[N], res[N];
vector <pii> adj[N];
vector <pii> v;
int ccw(pii x, pii y, pii z) {
	return (x.F*(y.S-z.S) + y.F*(z.S-x.S) + z.F*(x.S-y.S) >= 0);
}
void DP(int x, int p, ll d) {
	ll mn = 1e18;
	for (int i = 0; i < v.size(); i++) {
		mn = min(mn, v[i].F * b[x] + v[i].S);
	}
	if (v.empty()) mn = 0;
	mn += b[x]*d + a[x];
	pii pp = {-d, mn};
	while (v.size() > 1 && ccw(v[v.size()-2], v.back(), pp)) v.pop_back();
	v.pb(pp);
	
	for (auto it : v) cout << it.F << " " << it.S << "a\n";
	res[x] = mn;
	for (auto it : adj[x]) {
		if (it.F == p) continue;
		DP(it.F, x, d + it.S);
	}
}
int main()
{
	cin >> n;
	
	for (int i = 1; i < n; i++) {
		ll x, y, d; cin >> x >> y >> d;
		adj[x].pb({y, d});
		adj[y].pb({x, d});
	}
	
	for (int i = 2; i <= n; i++) {
		cin >> a[i] >> b[i];
	}
	
	DP(1, 0, 0);
	
	for (int i = 2; i <= n; i++) cout << res[i] << " ";
	return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
