Submission #12791770


Source Code Expand

//g++  5.4.0

#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<ll> adj[200005];
ll arr[200005];
ll LIS[200005];

void DFS(ll s,ll p,vector<ll> L)
{
    ll index = lower_bound(L.begin(),L.end(),arr[s]) - L.begin();
    
    if(index == (ll)L.size())
        L.push_back(arr[s]);
    else
        L[index] = arr[s];
    
    LIS[s] = L.size();
    
    for(ll i=0;i<adj[s].size();++i)
    {
        ll c = adj[s][i];
        if(c != p)
            DFS(c,s,L);
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll N; cin>>N;
    
    for(ll i=1;i<=N;++i)
        cin>>arr[i];
    
    vector<ll> L;
    L.push_back(LLONG_MAX);
    
    for(ll i=0;i<(N - 1);++i)
    {
        ll u,v; cin>>u>>v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    
    DFS(1,-1,L);
    
    for(ll i=1;i<=N;++i)
        cout<<LIS[i]<<endl;
    
}

Submission Info

Submission Time
Task F - LIS on Tree
User f20160363
Language C++ (GCC 9.2.1)
Score 0
Code Size 980 Byte
Status TLE
Exec Time 2324 ms
Memory 3497540 KiB

Compile Error

./Main.cpp: In function ‘void DFS(ll, ll, std::vector<long long int>)’:
./Main.cpp:22:17: warning: comparison of integer expressions of different signedness: ‘ll’ {aka ‘long long int’} and ‘std::vector<long long int>::size_type’ {aka ‘long unsigned int’} [-Wsign-compare]
   22 |     for(ll i=0;i<adj[s].size();++i)
      |                ~^~~~~~~~~~~~~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 600
Status
AC × 1
AC × 13
TLE × 4
Set Name Test Cases
Sample Sample_01.txt
All Sample_01.txt, caterpillar_01.txt, ni_01.txt, ni_02.txt, ni_03.txt, path_02.txt, path_04.txt, path_07.txt, path_08.txt, rand_01.txt, rand_02.txt, rand_03.txt, rand_04.txt, rand_05.txt, rand_large_01.txt, same_01.txt, star_01.txt
Case Name Status Exec Time Memory
Sample_01.txt AC 7 ms 8180 KiB
caterpillar_01.txt TLE 2322 ms 3483812 KiB
ni_01.txt AC 32 ms 9640 KiB
ni_02.txt AC 8 ms 8184 KiB
ni_03.txt AC 6 ms 8216 KiB
path_02.txt TLE 2324 ms 3497540 KiB
path_04.txt AC 1907 ms 512476 KiB
path_07.txt TLE 2206 ms 1036868 KiB
path_08.txt TLE 2323 ms 3496688 KiB
rand_01.txt AC 81 ms 10104 KiB
rand_02.txt AC 8 ms 8152 KiB
rand_03.txt AC 11 ms 8260 KiB
rand_04.txt AC 7 ms 8104 KiB
rand_05.txt AC 6 ms 8256 KiB
rand_large_01.txt AC 379 ms 18584 KiB
same_01.txt AC 975 ms 717552 KiB
star_01.txt AC 351 ms 18392 KiB