Submission #63035044
Source Code Expand
Copy
#include <bits/stdc++.h>using namespace std;const int N = 2e5 + 1;int n, x, y, cnt, head[N], f[N], ans;struct edge {int to, next;} a[N << 1];void add(int x, int y){a[++cnt] = {y, head[x]}, head[x] = cnt;}bool cmp(int x, int y){return x > y;}void dfs(int x, int fr)
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 1; int n, x, y, cnt, head[N], f[N], ans; struct edge { int to, next; } a[N << 1]; void add(int x, int y) { a[++cnt] = {y, head[x]}, head[x] = cnt; } bool cmp(int x, int y) { return x > y; } void dfs(int x, int fr) { vector<int> v; for (int i = head[x]; i; i = a[i].next) { if (a[i].to ^ fr) { dfs(a[i].to, x); v.push_back(f[a[i].to]); } } sort(v.begin(), v.end(), cmp); f[x] = 1; if (v.size() >= 4) { ans = max(ans, v[0] + v[1] + v[2] + v[3] + 1); } if (v.size() >= 3 && fr) { f[x] = v[0] + v[1] + v[2] + 1; ans = max(f[x] + 1, ans); } } signed main() { ios::sync_with_stdio(0); cin.tie(0), cout.tie(0); cin >> n; for (int i = 1; i < n; i++) cin >> x >> y, add(x, y), add(y, x); dfs(1, 0); cout << (ans == 0 ? -1 : ans); return 0; }
Submission Info
Submission Time | |
---|---|
Task | F - Alkane |
User | Wenhaocheng1205 |
Language | C++ 20 (gcc 12.2) |
Score | 500 |
Code Size | 1029 Byte |
Status | AC |
Exec Time | 61 ms |
Memory | 24332 KB |
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 | 3528 KB |
hand01.txt | AC | 1 ms | 3480 KB |
hand02.txt | AC | 1 ms | 3524 KB |
hand03.txt | AC | 1 ms | 3464 KB |
sample00.txt | AC | 1 ms | 3428 KB |
sample01.txt | AC | 1 ms | 3448 KB |
sample02.txt | AC | 1 ms | 3480 KB |
testcase00.txt | AC | 1 ms | 3332 KB |
testcase01.txt | AC | 1 ms | 3420 KB |
testcase02.txt | AC | 1 ms | 3420 KB |
testcase03.txt | AC | 1 ms | 3476 KB |
testcase04.txt | AC | 35 ms | 7832 KB |
testcase05.txt | AC | 39 ms | 8108 KB |
testcase06.txt | AC | 12 ms | 5324 KB |
testcase07.txt | AC | 40 ms | 8152 KB |
testcase08.txt | AC | 12 ms | 5184 KB |
testcase09.txt | AC | 39 ms | 8168 KB |
testcase10.txt | AC | 17 ms | 8284 KB |
testcase11.txt | AC | 49 ms | 16128 KB |
testcase12.txt | AC | 17 ms | 5940 KB |
testcase13.txt | AC | 42 ms | 8168 KB |
testcase14.txt | AC | 29 ms | 7184 KB |
testcase15.txt | AC | 41 ms | 8172 KB |
testcase16.txt | AC | 37 ms | 7860 KB |
testcase17.txt | AC | 39 ms | 8148 KB |
testcase18.txt | AC | 39 ms | 8176 KB |
testcase19.txt | AC | 38 ms | 8128 KB |
testcase20.txt | AC | 20 ms | 6284 KB |
testcase21.txt | AC | 39 ms | 8176 KB |
testcase22.txt | AC | 38 ms | 18016 KB |
testcase23.txt | AC | 61 ms | 24332 KB |
testcase24.txt | AC | 39 ms | 7896 KB |
testcase25.txt | AC | 42 ms | 8160 KB |
testcase26.txt | AC | 20 ms | 6120 KB |
testcase27.txt | AC | 43 ms | 8164 KB |
testcase28.txt | AC | 40 ms | 7952 KB |
testcase29.txt | AC | 42 ms | 8304 KB |
testcase30.txt | AC | 36 ms | 7616 KB |
testcase31.txt | AC | 42 ms | 8144 KB |
testcase32.txt | AC | 19 ms | 6196 KB |
testcase33.txt | AC | 41 ms | 8212 KB |
testcase34.txt | AC | 8 ms | 4588 KB |
testcase35.txt | AC | 41 ms | 8100 KB |
testcase36.txt | AC | 17 ms | 5848 KB |
testcase37.txt | AC | 40 ms | 8172 KB |
testcase38.txt | AC | 22 ms | 6512 KB |
testcase39.txt | AC | 43 ms | 7992 KB |
testcase40.txt | AC | 33 ms | 7324 KB |
testcase41.txt | AC | 41 ms | 8216 KB |
testcase42.txt | AC | 16 ms | 5704 KB |
testcase43.txt | AC | 41 ms | 8104 KB |
testcase44.txt | AC | 33 ms | 7548 KB |
testcase45.txt | AC | 40 ms | 8100 KB |
testcase46.txt | AC | 14 ms | 5492 KB |
testcase47.txt | AC | 40 ms | 8092 KB |
testcase48.txt | AC | 10 ms | 4940 KB |
testcase49.txt | AC | 41 ms | 8212 KB |
testcase50.txt | AC | 39 ms | 7940 KB |
testcase51.txt | AC | 41 ms | 8080 KB |