提出 #39635471


ソースコード 拡げる

#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
typedef long long ll;
using namespace std;
const int maxn = 2e5 + 5;
const int maxlog = 30;
const int inf = 0x3f3f3f3f;
int n, f[maxn][3][maxlog + 1], tmp[3][maxlog + 1];
vector<int> e[maxn];
void ckmin(int &x, int y) {
    x = y < x ? y : x;
}
void dfs(int u, int from) {
    f[u][0][1] = f[u][1][1] = f[u][2][1] = 1;
    for(int v : e[u]) {
        if(v == from) {
            continue;
        }
        dfs(v, u);
        memset(tmp, 0x3f, sizeof(tmp));
        for(int x = 0; x < 3; x++) {
            for(int i = 0; i <= maxlog; i++) {
                if(f[u][x][i] == inf) {
                    continue;
                }
                for(int y = 0; y < 3; y++) {
                    for(int j = 0; j <= maxlog; j++) {
                        int need = max(f[u][x][i], f[v][y][j]);
                        if(j < maxlog) {
                            ckmin(tmp[x][max(i, j + 1)], max(i + j, need));
                        }
                        if(x < 2 && y < 2) {
                            ckmin(tmp[x + 1][max(i, j)], max(i + j - 1, need));
                        }
                    }
                }
            }
        }
        for(int o = 0; o < 3; o++) {
            for(int i = 0; i <= maxlog; i++) {
                f[u][o][i] = tmp[o][i];
            }
        }
    }
}
int main() {
#ifdef DEBUG
	freopen("1.in", "r", stdin);
#endif
	ios::sync_with_stdio(0);
	cin.tie(0);
    cin >> n;
    for(int i = 1, u, v; i < n; i++) {
        cin >> u >> v;
        e[u].eb(v);
        e[v].eb(u);
    }
    memset(f, 0x3f, sizeof(f));
    dfs(1, 0);
    int ans = inf;
    for(int i = 0; i <= maxlog; i++) {
        ckmin(ans, f[1][2][i]);
    }
    cout << ans << '\n';
	return 0;
}

提出情報

提出日時
問題 Ex - Optimal Path Decomposition
ユーザ yanchengzhi
言語 C++ (GCC 9.2.1)
得点 600
コード長 1909 Byte
結果 AC
実行時間 513 ms
メモリ 114336 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 600 / 600
結果 AC
AC × 47
セット名 テストケース
Sample
All sample00.txt, sample01.txt, sample02.txt, testcase00.txt, testcase01.txt, testcase02.txt, testcase03.txt, testcase04.txt, testcase05.txt, testcase06.txt, testcase07.txt, testcase08.txt, testcase09.txt, testcase10.txt, testcase11.txt, testcase12.txt, testcase13.txt, testcase14.txt, testcase15.txt, testcase16.txt, testcase17.txt, testcase18.txt, testcase19.txt, testcase20.txt, testcase21.txt, testcase22.txt, testcase23.txt, testcase24.txt, testcase25.txt, testcase26.txt, testcase27.txt, testcase28.txt, testcase29.txt, testcase30.txt, testcase31.txt, testcase32.txt, testcase33.txt, testcase34.txt, testcase35.txt, testcase36.txt, testcase37.txt, testcase38.txt, testcase39.txt, testcase40.txt, testcase41.txt, testcase42.txt, testcase43.txt
ケース名 結果 実行時間 メモリ
sample00.txt AC 57 ms 80792 KiB
sample01.txt AC 55 ms 80792 KiB
sample02.txt AC 54 ms 80796 KiB
testcase00.txt AC 57 ms 80908 KiB
testcase01.txt AC 55 ms 80872 KiB
testcase02.txt AC 381 ms 110224 KiB
testcase03.txt AC 377 ms 114336 KiB
testcase04.txt AC 513 ms 107656 KiB
testcase05.txt AC 507 ms 109860 KiB
testcase06.txt AC 506 ms 109980 KiB
testcase07.txt AC 511 ms 109616 KiB
testcase08.txt AC 295 ms 86948 KiB
testcase09.txt AC 298 ms 86944 KiB
testcase10.txt AC 401 ms 86864 KiB
testcase11.txt AC 371 ms 86580 KiB
testcase12.txt AC 403 ms 87048 KiB
testcase13.txt AC 391 ms 86900 KiB
testcase14.txt AC 380 ms 86604 KiB
testcase15.txt AC 408 ms 87036 KiB
testcase16.txt AC 388 ms 86768 KiB
testcase17.txt AC 408 ms 87052 KiB
testcase18.txt AC 413 ms 87160 KiB
testcase19.txt AC 403 ms 86872 KiB
testcase20.txt AC 309 ms 87580 KiB
testcase21.txt AC 309 ms 87044 KiB
testcase22.txt AC 494 ms 87804 KiB
testcase23.txt AC 477 ms 87000 KiB
testcase24.txt AC 452 ms 86744 KiB
testcase25.txt AC 480 ms 87148 KiB
testcase26.txt AC 484 ms 87224 KiB
testcase27.txt AC 457 ms 86724 KiB
testcase28.txt AC 474 ms 87100 KiB
testcase29.txt AC 458 ms 87008 KiB
testcase30.txt AC 468 ms 87112 KiB
testcase31.txt AC 462 ms 87048 KiB
testcase32.txt AC 454 ms 87028 KiB
testcase33.txt AC 464 ms 87196 KiB
testcase34.txt AC 479 ms 87280 KiB
testcase35.txt AC 436 ms 86764 KiB
testcase36.txt AC 460 ms 87012 KiB
testcase37.txt AC 470 ms 87244 KiB
testcase38.txt AC 443 ms 86724 KiB
testcase39.txt AC 435 ms 86736 KiB
testcase40.txt AC 449 ms 87020 KiB
testcase41.txt AC 450 ms 86908 KiB
testcase42.txt AC 469 ms 87160 KiB
testcase43.txt AC 442 ms 86764 KiB