Submission #1824765
Source Code Expand
#define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <sstream> #include <iomanip> #include <cstdio> #include <cstdlib> #include <cmath> #include <cctype> #include <cstring> #include <vector> #include <list> #include <queue> #include <deque> #include <stack> #include <map> #include <set> #include <algorithm> #include <iterator> #include <bitset> #include <ctime> #include<complex> using namespace std; #define FOR(i,a,b) for (int i = (a); i < (b); i++) #define RFOR(i,b,a) for (int i = (b)-1; i >= (a); i--) #define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++) #define FILL(a,value) memset(a, value, sizeof(a)) #define SZ(a) (int)a.size() #define ALL(a) a.begin(), a.end() #define PB push_back #define MP make_pair typedef long long LL; typedef vector<int> VI; typedef pair<int, int> PII; typedef pair<long long, long long> PLL; const double PI = acos(-1.0); const int INF = 1000 * 1000 * 1000 + 7; const LL LINF = INF * (LL)INF; const int MAX = 2 * 1000 * 100 + 47; vector<PII> g[MAX]; vector<PLL> A[MAX]; int sz; bool cmp(PLL a, PLL b) { return a.second < b.second; } int dfs(int v, LL T) { if (SZ(g[v]) == 0) { A[sz].push_back(MP(0, 0)); sz++; return sz - 1; } int i1 = dfs(g[v][0].first, T); int i2 = dfs(g[v][1].first, T); int vi = g[v][0].second; int vk = g[v][1].second; int p = 0; sort(ALL(A[i1]), cmp); sort(ALL(A[i2])); LL mind = LINF; RFOR(i, SZ(A[i1]), 0) { LL a = A[i1][i].first; LL b = A[i1][i].second; while (p != SZ(A[i2]) && b + A[i2][p].first + vi + vk <= T) { mind = min(A[i2][p].second, mind); p++; } if (mind == LINF) continue; A[sz].push_back(MP(a + vi, mind + vk)); } sort(ALL(A[i1])); sort(ALL(A[i2]), cmp); LL minc = LINF; p = 0; RFOR(i,SZ(A[i1]), 0) { LL a = A[i1][i].first; LL b = A[i1][i].second; while (p != SZ(A[i2]) && a + A[i2][p].second + vi + vk <= T) { minc = min(minc, A[i2][p].first); p++; } if (minc == LINF) continue; A[sz].push_back(MP(minc + vk, b + vi)); } sz++; return sz - 1; } bool ok(LL c) { FOR(i, 0, sz) A[i].clear(); sz = 0; int ind = dfs(0, c); return SZ(A[ind]); } int main() { //freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout); ios::sync_with_stdio(false); cin.tie(0); int n, p, v; cin >> n; FOR(i, 0, n - 1) { cin >> p >> v; p--; g[p].push_back(MP(i + 1, v)); } LL l = -1, r = 1000 * (LL)1000 * (LL)1000 * (LL)1000; while (r - l > 1) { //cout << l << " " << r << endl; LL c = (r + l) / 2; if (ok(c)) { r = c; } else { l = c; } } cout << r << endl; }
Submission Info
Submission Time | |
---|---|
Task | E - Shik and Travel |
User | vjudge1 |
Language | Bash (GNU bash v4.3.11) |
Score | 0 |
Code Size | 2591 Byte |
Status | RE |
Exec Time | 5 ms |
Memory | 604 KB |
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 | RE | 4 ms | 580 KB |
001.txt | RE | 4 ms | 572 KB |
002.txt | RE | 4 ms | 580 KB |
003.txt | RE | 4 ms | 576 KB |
004.txt | RE | 4 ms | 580 KB |
005.txt | RE | 4 ms | 576 KB |
006.txt | RE | 4 ms | 576 KB |
007.txt | RE | 4 ms | 576 KB |
008.txt | RE | 4 ms | 576 KB |
009.txt | RE | 4 ms | 568 KB |
010.txt | RE | 4 ms | 576 KB |
011.txt | RE | 4 ms | 584 KB |
012.txt | RE | 4 ms | 580 KB |
013.txt | RE | 4 ms | 580 KB |
014.txt | RE | 4 ms | 568 KB |
015.txt | RE | 4 ms | 576 KB |
016.txt | RE | 4 ms | 604 KB |
017.txt | RE | 4 ms | 572 KB |
018.txt | RE | 4 ms | 576 KB |
019.txt | RE | 4 ms | 604 KB |
020.txt | RE | 4 ms | 576 KB |
021.txt | RE | 4 ms | 580 KB |
022.txt | RE | 4 ms | 576 KB |
023.txt | RE | 4 ms | 600 KB |
024.txt | RE | 4 ms | 576 KB |
025.txt | RE | 4 ms | 576 KB |
026.txt | RE | 4 ms | 576 KB |
027.txt | RE | 4 ms | 588 KB |
028.txt | RE | 4 ms | 576 KB |
029.txt | RE | 4 ms | 576 KB |
030.txt | RE | 4 ms | 572 KB |
031.txt | RE | 4 ms | 588 KB |
032.txt | RE | 4 ms | 584 KB |
033.txt | RE | 4 ms | 572 KB |
034.txt | RE | 4 ms | 572 KB |
035.txt | RE | 4 ms | 580 KB |
036.txt | RE | 4 ms | 576 KB |
037.txt | RE | 4 ms | 580 KB |
038.txt | RE | 4 ms | 576 KB |
039.txt | RE | 4 ms | 588 KB |
040.txt | RE | 4 ms | 580 KB |
041.txt | RE | 4 ms | 580 KB |
042.txt | RE | 4 ms | 588 KB |
043.txt | RE | 4 ms | 580 KB |
044.txt | RE | 4 ms | 580 KB |
045.txt | RE | 4 ms | 572 KB |
046.txt | RE | 5 ms | 576 KB |
047.txt | RE | 4 ms | 572 KB |
048.txt | RE | 4 ms | 576 KB |
049.txt | RE | 4 ms | 584 KB |
example0.txt | RE | 4 ms | 576 KB |
example1.txt | RE | 4 ms | 580 KB |
example2.txt | RE | 4 ms | 572 KB |
example3.txt | RE | 4 ms | 576 KB |