| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 | 
|---|---|---|---|---|---|---|---|
| 209994 | SamAnd | Putovanje (COCI20_putovanje) | C++17 | 200 ms | 32760 KiB | 
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
const int N = 200005;
int n;
vector<int> a[N];
vector<pair<int, int> > b[N];
int tin[N], tout[N], ti;
const int m = 19;
int p[N][m];
void dfs0(int x, int p0)
{
    tin[x] = ++ti;
    p[x][0] = p0;
    for (int i = 1; i < m; ++i)
        p[x][i] = p[p[x][i - 1]][i - 1];
    for (int i = 0; i < a[x].size(); ++i)
    {
        int h = a[x][i];
        if (h == p0)
            continue;
        dfs0(h, x);
    }
    tout[x] = ti;
}
bool isp(int x, int y)
{
    return (tin[x] <= tin[y] && tin[y] <= tout[x]);
}
int lca(int x, int y)
{
    if (isp(x, y))
        return x;
    if (isp(y, x))
        return y;
    for (int i = m - 1; i >= 0; --i)
    {
        if (!isp(p[x][i], y))
            x = p[x][i];
    }
    return p[x][0];
}
long long ans;
int q[N];
void dfs(int x, int p)
{
    for (int i = 0; i < a[x].size(); ++i)
    {
        int h = a[x][i];
        if (h == p)
            continue;
        dfs(h, x);
        q[x] += q[h];
    }
    for (int i = 0; i < a[x].size(); ++i)
    {
        int h = a[x][i];
        if (h == p)
        {
            ans += min(b[x][i].second * 1LL, b[x][i].first * 1LL * q[x]);
        }
    }
}
int main()
{
    scanf("%d", &n);
    for (int i = 0; i < n - 1; ++i)
    {
        int x, y, c1, c2;
        scanf("%d%d%d%d", &x, &y, &c1, &c2);
        a[x].push_back(y);
        a[y].push_back(x);
        b[x].push_back(m_p(c1, c2));
        b[y].push_back(m_p(c1, c2));
    }
    dfs0(1, 1);
    for (int i = 1; i < n; ++i)
    {
        int u = lca(i, i + 1);
        q[u] -= 2;
        q[i]++;
        q[i + 1]++;
    }
    dfs(1, 1);
    printf("%lld\n", ans);
    return 0;
}
컴파일 시 표준 에러 (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... | ||||
