Submission #1825633
Source Code Expand
#include <cstdio> #include <cstring> #include <algorithm> #include <vector> using namespace std; const int maxn = 2e5; int n, son[maxn][2], len[maxn]; long long ans; typedef pair<long long, long long> Pair; vector<Pair> set[maxn]; void Combine(vector<Pair> &s, int u, int v) { s.clear(); if (set[u].empty()) { return; } for (int i = 0, j = 0; i < set[u].size(); ++i) { if (len[u] + len[v] + set[u][i].second + set[v][j].first > ans) { continue; } while (j + 1 < set[v].size() && len[u] + len[v] + set[u][i].second + set[v][j + 1].first <= ans) { ++j; } s.push_back(Pair(len[u] + set[u][i].first, len[v] + set[v][j].second)); } int m = s.size(); for (int i = set[u].size() - 1, j = set[v].size() - 1; i >= 0; --i) { if (len[u] + len[v] + set[v][j].second + set[u][i].first > ans) { continue; } while (j > 0 && len[u] + len[v] + set[v][j - 1].second + set[u][i].first <= ans) { --j; } s.push_back(Pair(len[v] + set[v][j].first, len[u] + set[u][i].second)); } inplace_merge(s.begin(), s.begin() + m, s.end()); m = 0; for (int i = 0; i < s.size(); ++i) { if (i == 0 || s[i].second < s[i - 1].second) { s[m++] = s[i]; } } s.resize(m); } bool Check(void) { for (int i = n - 1; i >= 0; --i) { if (son[i][0] == -1) { set[i] = {Pair(0, 0)}; } else { int &u = son[i][0], &v = son[i][1]; if (set[u].size() > set[v].size()) { swap(u, v); } Combine(set[i], u, v); } } return set[0].size(); } int main(void) { scanf("%d", &n); memset(son, -1, sizeof son); for (int i = 1; i < n; ++i) { int par; scanf("%d%d", &par, len + i); --par; swap(son[par][0], son[par][1]); son[par][0] = i; } long long low = 0, high = (long long)maxn * maxn; while (low < high) { long long mid = low + high >> 1; ans = mid; if (Check()) { high = mid; } else { low = mid + 1; } } printf("%lld\n", low); return 0; }
Submission Info
Submission Time | |
---|---|
Task | E - Shik and Travel |
User | orbitingflea |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 2147 Byte |
Status | WA |
Exec Time | 284 ms |
Memory | 15488 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:66:18: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d", &n); ^ ./Main.cpp:70:33: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d%d", &par, len + 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 | WA | 7 ms | 7296 KB |
001.txt | WA | 7 ms | 7296 KB |
002.txt | WA | 7 ms | 7296 KB |
003.txt | WA | 7 ms | 7296 KB |
004.txt | WA | 7 ms | 7296 KB |
005.txt | WA | 7 ms | 7296 KB |
006.txt | AC | 7 ms | 7296 KB |
007.txt | AC | 7 ms | 7296 KB |
008.txt | WA | 7 ms | 7296 KB |
009.txt | WA | 7 ms | 7296 KB |
010.txt | WA | 246 ms | 13056 KB |
011.txt | WA | 251 ms | 13056 KB |
012.txt | WA | 248 ms | 13056 KB |
013.txt | WA | 241 ms | 13056 KB |
014.txt | WA | 251 ms | 13056 KB |
015.txt | WA | 249 ms | 13056 KB |
016.txt | WA | 250 ms | 13056 KB |
017.txt | WA | 252 ms | 13056 KB |
018.txt | WA | 253 ms | 13056 KB |
019.txt | WA | 255 ms | 13056 KB |
020.txt | WA | 246 ms | 13056 KB |
021.txt | WA | 251 ms | 13056 KB |
022.txt | WA | 243 ms | 13056 KB |
023.txt | WA | 245 ms | 13056 KB |
024.txt | WA | 247 ms | 13056 KB |
025.txt | WA | 249 ms | 13056 KB |
026.txt | AC | 236 ms | 12672 KB |
027.txt | WA | 242 ms | 13056 KB |
028.txt | AC | 239 ms | 12672 KB |
029.txt | AC | 236 ms | 12672 KB |
030.txt | WA | 235 ms | 13440 KB |
031.txt | WA | 256 ms | 13440 KB |
032.txt | WA | 284 ms | 13440 KB |
033.txt | WA | 236 ms | 13440 KB |
034.txt | WA | 233 ms | 13440 KB |
035.txt | WA | 250 ms | 13440 KB |
036.txt | WA | 232 ms | 13440 KB |
037.txt | WA | 238 ms | 13184 KB |
038.txt | WA | 230 ms | 13440 KB |
039.txt | AC | 207 ms | 12416 KB |
040.txt | AC | 176 ms | 14976 KB |
041.txt | AC | 217 ms | 15488 KB |
042.txt | AC | 217 ms | 15488 KB |
043.txt | AC | 216 ms | 15488 KB |
044.txt | AC | 154 ms | 12416 KB |
045.txt | AC | 178 ms | 12416 KB |
046.txt | AC | 182 ms | 12416 KB |
047.txt | AC | 182 ms | 12416 KB |
048.txt | AC | 187 ms | 12416 KB |
049.txt | AC | 4 ms | 7296 KB |
example0.txt | AC | 4 ms | 7296 KB |
example1.txt | AC | 4 ms | 7296 KB |
example2.txt | AC | 4 ms | 7296 KB |
example3.txt | AC | 4 ms | 7296 KB |