Submission #1884022
Source Code Expand
// Shik and Travel // * frank_c1 // * 2017 / 12 / 18 #include <bits/stdc++.h> using namespace std; typedef pair<int, int> pii; const int maxn = (1 << 17) + 5; int wi[maxn], ai[maxn], bi[maxn]; int st[maxn], su[maxn]; pii ci[maxn * 17], ta[maxn], tb[maxn]; int n, idx; bool chk(int x) { idx = 0; for (int i = n; i >= 1; --i) { st[i] = idx + 1; if (!ai[i]) ci[++idx] = make_pair(0, 0); else { int u = ai[i], v = bi[i]; if (su[u] > su[v]) swap(u, v); int mx = x - wi[u] - wi[v]; int ca = 0, cb = 0, ww = (int)(1e9), ps = 1; for (int j = st[u]; j < st[u] + su[u]; ++j) ta[++ca] = make_pair(ci[j].first, ci[j].second); for (int j = st[v]; j < st[v] + su[v]; ++j) tb[++cb] = make_pair(ci[j].second, ci[j].first); sort(ta + 1, ta + ca + 1); sort(tb + 1, tb + cb + 1); for (int j = ca; j >= 1; --j) { while (ps <= cb && ta[j].first + tb[ps].first <= mx) ww = min(ww, tb[ps++].second); if (ps > 1) ci[++idx] = make_pair(ww + wi[v], ta[j].second + wi[u]); } ca = cb = 0; ww = (int)(1e9); ps = 1; for (int j = st[u]; j < st[u] + su[u]; ++j) ta[++ca] = make_pair(ci[j].second, ci[j].first); for (int j = st[v]; j < st[v] + su[v]; ++j) tb[++cb] = make_pair(ci[j].first, ci[j].second); sort(ta + 1, ta + ca + 1); sort(tb + 1, tb + cb + 1); for (int j = ca; j >= 1; --j) { while (ps <= cb && ta[j].first + tb[ps].first <= mx) ww = min(ww, tb[ps++].second); if (ps > 1) ci[++idx] = make_pair(ta[j].second + wi[u], ww + wi[v]); } } su[i] = idx - st[i] + 1; } return su[1] > 0; } int main() { scanf("%d", &n); for (int i = 2; i <= n; ++i) { int f; scanf("%d%d", &f, &wi[i]); if (!ai[f]) ai[f] = i; else bi[f] = i; } int l = 0, r = 17 * (1 << 17); while (l < r) { int mid = (l + r) >> 1; if (chk(mid)) r = mid; else l = mid + 1; } return printf("%d\n", l), 0; }
Submission Info
Submission Time | |
---|---|
Task | E - Shik and Travel |
User | frank_c1 |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 1895 Byte |
Status | WA |
Exec Time | 740 ms |
Memory | 14592 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:47:17: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d", &n); ^ ./Main.cpp:49:35: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] int f; scanf("%d%d", &f, &wi[i]); ^
Judge Result
Set Name | Sample | All | ||||||
---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 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 | 4 ms | 4352 KB |
001.txt | AC | 4 ms | 4352 KB |
002.txt | AC | 4 ms | 4352 KB |
003.txt | AC | 4 ms | 4352 KB |
004.txt | AC | 4 ms | 4352 KB |
005.txt | AC | 4 ms | 4352 KB |
006.txt | AC | 4 ms | 4352 KB |
007.txt | AC | 4 ms | 4352 KB |
008.txt | AC | 4 ms | 4352 KB |
009.txt | AC | 4 ms | 4352 KB |
010.txt | AC | 160 ms | 7936 KB |
011.txt | AC | 159 ms | 7936 KB |
012.txt | AC | 157 ms | 7936 KB |
013.txt | AC | 158 ms | 7936 KB |
014.txt | AC | 158 ms | 7936 KB |
015.txt | AC | 158 ms | 7936 KB |
016.txt | AC | 158 ms | 7936 KB |
017.txt | AC | 165 ms | 7936 KB |
018.txt | AC | 158 ms | 7936 KB |
019.txt | AC | 163 ms | 7936 KB |
020.txt | AC | 158 ms | 7936 KB |
021.txt | AC | 160 ms | 7936 KB |
022.txt | AC | 159 ms | 7936 KB |
023.txt | AC | 159 ms | 7936 KB |
024.txt | AC | 160 ms | 7936 KB |
025.txt | AC | 159 ms | 7936 KB |
026.txt | AC | 158 ms | 7936 KB |
027.txt | AC | 158 ms | 7936 KB |
028.txt | AC | 158 ms | 7936 KB |
029.txt | AC | 159 ms | 7936 KB |
030.txt | AC | 671 ms | 14080 KB |
031.txt | AC | 706 ms | 14592 KB |
032.txt | AC | 740 ms | 14592 KB |
033.txt | AC | 659 ms | 14080 KB |
034.txt | AC | 683 ms | 14080 KB |
035.txt | WA | 373 ms | 9984 KB |
036.txt | WA | 328 ms | 9472 KB |
037.txt | WA | 334 ms | 9472 KB |
038.txt | WA | 324 ms | 9472 KB |
039.txt | WA | 240 ms | 9984 KB |
040.txt | AC | 654 ms | 14080 KB |
041.txt | AC | 717 ms | 14592 KB |
042.txt | AC | 717 ms | 14592 KB |
043.txt | AC | 717 ms | 14592 KB |
044.txt | AC | 81 ms | 5888 KB |
045.txt | AC | 96 ms | 5888 KB |
046.txt | AC | 96 ms | 5888 KB |
047.txt | AC | 96 ms | 5888 KB |
048.txt | AC | 96 ms | 5888 KB |
049.txt | AC | 2 ms | 4352 KB |
example0.txt | AC | 2 ms | 4352 KB |
example1.txt | AC | 2 ms | 4352 KB |
example2.txt | AC | 2 ms | 4352 KB |
example3.txt | AC | 2 ms | 4352 KB |