Please sign in first.
Submission #63140699
Source Code Expand
#include <bits/stdc++.h> using namespace std; #define fre(x) freopen(#x".in", "r", stdin); freopen(#x".out", "w", stdout) #define ck(x) { cout << "check " << x << "\n"; cout.flush();} #define int long long #define double long double #define inf 0x3fffffffffffffff //-------------- templates above -------------- void solve() { int n; cin >> n; vector<vector<int>> adj(n + 1); for (int i = 1; i < n; i++) { int x, y; cin >> x >> y; adj[x].push_back(y); adj[y].push_back(x); } vector<int> dp(n + 1, 1); int ans = -1; auto dfs = [&] (auto self, int x, int fa) -> void { vector<int> a; for (auto y : adj[x]) { if (y == fa) { continue; } self(self, y, x); a.push_back(dp[y]); if (adj[x].size() >= 1 && adj[y].size() >= 4) { ans = max(ans, dp[y] + 1); } } sort(a.begin(), a.end(), greater()); if (a.size() >= 4) { ans = max(ans, a[0] + a[1] + a[2] + a[3] + 1); } if (a.size() >= 3) { dp[x] = a[0] + a[1] + a[2] + 1; } }; dfs(dfs, 1, 0); cout << ans << "\n"; } signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); int T = 1; while (T--) { solve(); } return 0; }
Submission Info
Submission Time | |
---|---|
Task | F - Alkane |
User | KisuraOP |
Language | C++ 20 (gcc 12.2) |
Score | 500 |
Code Size | 1205 Byte |
Status | AC |
Exec Time | 139 ms |
Memory | 43428 KiB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 500 / 500 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | sample00.txt, sample01.txt, sample02.txt |
All | hand00.txt, hand01.txt, hand02.txt, hand03.txt, 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, testcase44.txt, testcase45.txt, testcase46.txt, testcase47.txt, testcase48.txt, testcase49.txt, testcase50.txt, testcase51.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
hand00.txt | AC | 1 ms | 3556 KiB |
hand01.txt | AC | 1 ms | 3508 KiB |
hand02.txt | AC | 1 ms | 3512 KiB |
hand03.txt | AC | 1 ms | 3400 KiB |
sample00.txt | AC | 1 ms | 3428 KiB |
sample01.txt | AC | 1 ms | 3368 KiB |
sample02.txt | AC | 1 ms | 3560 KiB |
testcase00.txt | AC | 1 ms | 3472 KiB |
testcase01.txt | AC | 1 ms | 3632 KiB |
testcase02.txt | AC | 1 ms | 3436 KiB |
testcase03.txt | AC | 1 ms | 3512 KiB |
testcase04.txt | AC | 95 ms | 15440 KiB |
testcase05.txt | AC | 111 ms | 16452 KiB |
testcase06.txt | AC | 26 ms | 8468 KiB |
testcase07.txt | AC | 108 ms | 16532 KiB |
testcase08.txt | AC | 25 ms | 8032 KiB |
testcase09.txt | AC | 102 ms | 16480 KiB |
testcase10.txt | AC | 34 ms | 13520 KiB |
testcase11.txt | AC | 118 ms | 29420 KiB |
testcase12.txt | AC | 42 ms | 10412 KiB |
testcase13.txt | AC | 107 ms | 16500 KiB |
testcase14.txt | AC | 84 ms | 13876 KiB |
testcase15.txt | AC | 105 ms | 16512 KiB |
testcase16.txt | AC | 98 ms | 15856 KiB |
testcase17.txt | AC | 108 ms | 16548 KiB |
testcase18.txt | AC | 107 ms | 16644 KiB |
testcase19.txt | AC | 103 ms | 16640 KiB |
testcase20.txt | AC | 49 ms | 10960 KiB |
testcase21.txt | AC | 108 ms | 16548 KiB |
testcase22.txt | AC | 86 ms | 31156 KiB |
testcase23.txt | AC | 139 ms | 43428 KiB |
testcase24.txt | AC | 106 ms | 17248 KiB |
testcase25.txt | AC | 117 ms | 17812 KiB |
testcase26.txt | AC | 51 ms | 10952 KiB |
testcase27.txt | AC | 122 ms | 17444 KiB |
testcase28.txt | AC | 113 ms | 16532 KiB |
testcase29.txt | AC | 119 ms | 17276 KiB |
testcase30.txt | AC | 107 ms | 15684 KiB |
testcase31.txt | AC | 122 ms | 17296 KiB |
testcase32.txt | AC | 51 ms | 10656 KiB |
testcase33.txt | AC | 117 ms | 16836 KiB |
testcase34.txt | AC | 15 ms | 6168 KiB |
testcase35.txt | AC | 118 ms | 16820 KiB |
testcase36.txt | AC | 43 ms | 9976 KiB |
testcase37.txt | AC | 116 ms | 16736 KiB |
testcase38.txt | AC | 59 ms | 11492 KiB |
testcase39.txt | AC | 119 ms | 16840 KiB |
testcase40.txt | AC | 91 ms | 14424 KiB |
testcase41.txt | AC | 118 ms | 16772 KiB |
testcase42.txt | AC | 37 ms | 9124 KiB |
testcase43.txt | AC | 123 ms | 16768 KiB |
testcase44.txt | AC | 95 ms | 14664 KiB |
testcase45.txt | AC | 118 ms | 16716 KiB |
testcase46.txt | AC | 35 ms | 8824 KiB |
testcase47.txt | AC | 115 ms | 16776 KiB |
testcase48.txt | AC | 21 ms | 7356 KiB |
testcase49.txt | AC | 119 ms | 16748 KiB |
testcase50.txt | AC | 109 ms | 16208 KiB |
testcase51.txt | AC | 113 ms | 16856 KiB |