Submission #980851


Source Code Expand

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#define PB push_back
#define MP make_pair
#define sz(v) (in((v).size()))
#define forn(i,n) for(in i=0;i<(n);++i)
#define forv(i,v) forn(i,sz(v))
#define fors(i,s) for(auto i=(s).begin();i!=(s).end();++i)
#define all(v) (v).begin(),(v).end()
using namespace std;
typedef long long in;
typedef vector<in> VI;
typedef vector<VI> VVI;
VVI cd,cl;
const in inf=1e15;
in tt;
in bv(in u, in lf){
  if(lf<0)
    return inf;
  if(sz(cd[u])==0)
    return 0;
  assert(sz(cd[u])==2);
  in bst=inf;
  in a;
  forn(z,2){
    a=bv(cd[u][z],lf-cl[u][z])+cl[u][z];
    a=bv(cd[u][!z],tt-(a+cl[u][!z]))+cl[u][!z];
    bst=min(bst,a);
  }
  return bst;
}
bool isp(in mx){
  tt=mx;
  in a=bv(cd[0][0],inf)+cl[0][0];
  a=bv(cd[0][1],tt-(a+cl[0][1]))+cl[0][1];
  if(a<inf)
    return 1;
  return 0;
}
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  in n;
  cin>>n;
  cd.resize(n);
  cl.resize(n);
  in a,v;
  forn(i,n-1){
    cin>>a>>v;
    cd[a-1].PB(i+1);
    cl[a-1].PB(v);
  }
  in mn=-1;
  in mx=inf;
  in md;
  while(mx-mn>1){
    md=(mx+mn)/2;
    if(isp(md))
      mx=md;
    else
      mn=md;
  }
  cout<<mx<<endl;
  return 0;
}

Submission Info

Submission Time
Task E - Shik and Travel
User w4yneb0t
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1311 Byte
Status TLE
Exec Time 5255 ms
Memory 15616 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 1400
Status
AC × 4
AC × 8
TLE × 46
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 TLE 5254 ms 384 KB
001.txt TLE 5254 ms 384 KB
002.txt AC 1427 ms 384 KB
003.txt TLE 5254 ms 384 KB
004.txt TLE 5254 ms 384 KB
005.txt TLE 5254 ms 384 KB
006.txt TLE 5254 ms 384 KB
007.txt AC 2820 ms 384 KB
008.txt TLE 5254 ms 384 KB
009.txt AC 1624 ms 384 KB
010.txt TLE 5254 ms 10496 KB
011.txt TLE 5255 ms 10496 KB
012.txt TLE 5255 ms 10496 KB
013.txt TLE 5254 ms 10496 KB
014.txt TLE 5255 ms 10496 KB
015.txt TLE 5255 ms 10496 KB
016.txt TLE 5255 ms 10496 KB
017.txt TLE 5254 ms 10496 KB
018.txt TLE 5255 ms 10496 KB
019.txt TLE 5254 ms 10496 KB
020.txt TLE 5254 ms 10496 KB
021.txt TLE 5255 ms 10496 KB
022.txt TLE 5255 ms 10496 KB
023.txt TLE 5255 ms 10496 KB
024.txt TLE 5255 ms 10496 KB
025.txt TLE 5254 ms 10496 KB
026.txt TLE 5255 ms 10496 KB
027.txt TLE 5255 ms 10496 KB
028.txt TLE 5255 ms 10496 KB
029.txt TLE 5255 ms 10496 KB
030.txt TLE 5254 ms 10496 KB
031.txt TLE 5255 ms 10496 KB
032.txt TLE 5254 ms 10496 KB
033.txt TLE 5255 ms 10496 KB
034.txt TLE 5255 ms 10496 KB
035.txt TLE 5254 ms 10496 KB
036.txt TLE 5254 ms 10496 KB
037.txt TLE 5255 ms 10496 KB
038.txt TLE 5255 ms 10496 KB
039.txt TLE 5255 ms 10496 KB
040.txt TLE 5255 ms 10496 KB
041.txt TLE 5255 ms 10496 KB
042.txt TLE 5254 ms 10496 KB
043.txt TLE 5255 ms 10496 KB
044.txt TLE 5255 ms 15616 KB
045.txt TLE 5255 ms 13056 KB
046.txt TLE 5255 ms 12288 KB
047.txt TLE 5255 ms 12800 KB
048.txt TLE 5255 ms 14848 KB
049.txt AC 3 ms 256 KB
example0.txt AC 3 ms 384 KB
example1.txt AC 3 ms 256 KB
example2.txt AC 3 ms 256 KB
example3.txt AC 3 ms 256 KB