Submission #1611277
Source Code Expand
#include <cstdio> #include <algorithm> #include <vector> using namespace std; #define iter(i, n) forw(i, 1, n) #define forw(i, a, b) for (int i = a; i <= b; ++i) typedef long long i64; #define NR 201000 typedef pair<i64, i64> pii; #define fi first #define se second int n, lc[NR], rc[NR], fw[NR]; vector<pii> vec[NR]; i64 lim; void dfs(int x) { // printf("d %d %d %d\n", x, lc[x], rc[x]); if (lc[x] == 0) { vec[x].push_back(pii(0, 0)); return; } int i = lc[x], j = rc[x]; dfs(i); dfs(j); if (vec[i].size() > vec[j].size()) swap(i, j); vector<pii> tmp; vec[x].clear(); for (pii p : vec[i]) { int index = lower_bound(vec[j].begin(), vec[j].end(), pii(lim - p.se - fw[i] - fw[j] + 1, 0)) - vec[j].begin(); // printf("!!%lld %lld %d\n", lim, lim - p.se - fw[i] - fw[j] + 1, index); if (index > 0) { --index; tmp.push_back(pii(p.fi + fw[i], vec[j][index].se + fw[j])); tmp.push_back(pii(vec[j][index].se + fw[j], p.fi + fw[i])); } } sort(tmp.begin(), tmp.end()); i64 lst = 1e12; for (pii p : tmp) if (p.se < lst) vec[x].push_back(p), lst = p.se; } bool check(i64 l) { lim = l; dfs(1); return !vec[1].empty(); } int main() { scanf("%d", &n); forw(i, 2, n) { int fa; scanf("%d%d", &fa, &fw[i]); if (lc[fa]) rc[fa] = i; else lc[fa] = i; } i64 l = 0, r = 1e11; for (; l < r;) { i64 mid = (l + r) / 2; if (check(mid)) r = mid; else l = mid + 1; } printf("%lld\n", l); return 0; }
Submission Info
Submission Time | |
---|---|
Task | E - Shik and Travel |
User | Ketsui |
Language | C++14 (GCC 5.4.1) |
Score | 1400 |
Code Size | 1517 Byte |
Status | AC |
Exec Time | 1845 ms |
Memory | 95492 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:57:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d", &n); ^ ./Main.cpp:60:29: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d%d", &fa, &fw[i]); ^
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 1400 / 1400 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | example0.txt, example1.txt, example2.txt, example3.txt |
All | 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, 026.txt, 027.txt, 028.txt, 029.txt, 030.txt, 031.txt, 032.txt, 033.txt, 034.txt, 035.txt, 036.txt, 037.txt, 038.txt, 039.txt, 040.txt, 041.txt, 042.txt, 043.txt, 044.txt, 045.txt, 046.txt, 047.txt, 048.txt, 049.txt, example0.txt, example1.txt, example2.txt, example3.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
000.txt | AC | 21 ms | 7552 KB |
001.txt | AC | 22 ms | 7424 KB |
002.txt | AC | 21 ms | 7424 KB |
003.txt | AC | 22 ms | 7424 KB |
004.txt | AC | 21 ms | 7424 KB |
005.txt | AC | 21 ms | 7424 KB |
006.txt | AC | 21 ms | 7552 KB |
007.txt | AC | 21 ms | 7424 KB |
008.txt | AC | 22 ms | 7424 KB |
009.txt | AC | 22 ms | 7424 KB |
010.txt | AC | 1425 ms | 78976 KB |
011.txt | AC | 1486 ms | 78976 KB |
012.txt | AC | 1422 ms | 78976 KB |
013.txt | AC | 1412 ms | 78976 KB |
014.txt | AC | 1353 ms | 78976 KB |
015.txt | AC | 1408 ms | 78976 KB |
016.txt | AC | 1457 ms | 78976 KB |
017.txt | AC | 1361 ms | 78976 KB |
018.txt | AC | 1432 ms | 78976 KB |
019.txt | AC | 1334 ms | 78848 KB |
020.txt | AC | 1345 ms | 78976 KB |
021.txt | AC | 1392 ms | 78848 KB |
022.txt | AC | 1409 ms | 78976 KB |
023.txt | AC | 1422 ms | 78976 KB |
024.txt | AC | 1401 ms | 78976 KB |
025.txt | AC | 1392 ms | 78976 KB |
026.txt | AC | 1294 ms | 78336 KB |
027.txt | AC | 1406 ms | 78976 KB |
028.txt | AC | 1409 ms | 78336 KB |
029.txt | AC | 1293 ms | 78336 KB |
030.txt | AC | 1725 ms | 78720 KB |
031.txt | AC | 1632 ms | 78976 KB |
032.txt | AC | 1676 ms | 78976 KB |
033.txt | AC | 1580 ms | 78720 KB |
034.txt | AC | 1659 ms | 78720 KB |
035.txt | AC | 1845 ms | 78976 KB |
036.txt | AC | 1738 ms | 78720 KB |
037.txt | AC | 1668 ms | 78464 KB |
038.txt | AC | 1752 ms | 78720 KB |
039.txt | AC | 1498 ms | 77952 KB |
040.txt | AC | 1714 ms | 94980 KB |
041.txt | AC | 1786 ms | 95492 KB |
042.txt | AC | 1801 ms | 95492 KB |
043.txt | AC | 1788 ms | 95492 KB |
044.txt | AC | 534 ms | 86144 KB |
045.txt | AC | 694 ms | 81536 KB |
046.txt | AC | 674 ms | 82816 KB |
047.txt | AC | 654 ms | 81920 KB |
048.txt | AC | 660 ms | 84608 KB |
049.txt | AC | 3 ms | 6400 KB |
example0.txt | AC | 3 ms | 6400 KB |
example1.txt | AC | 3 ms | 6400 KB |
example2.txt | AC | 3 ms | 6400 KB |
example3.txt | AC | 3 ms | 6400 KB |