Submission #1361084

#TimeUsernameProblemLanguageResultExecution timeMemory
1361084eyadoozMagic Tree (CEOI19_magictree)C++20
Compilation error
0 ms0 KiB
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define pb push_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int) (x).size()
#define endl '\n'
#define int long long
int fa[100005], a[100005], dp[100005][5001], mxd;
        // int prefmx[1001]={};
vector<int> adj[100005];
void init(int x, int p=-1) 
{
    dp[x][a[x]]+=fa[x];
    for(auto i : adj[x]) 
    {
        if(i==p) continue;
        init(i, x);
        int cnt=0;
        for(int j = 1;j<=mxd;j++) 
        {
            cnt=max(cnt, dp[i][j]);
            dp[x][j]+=cnt;
        }
    }
}
main()
{
    cin.tie(0) -> sync_with_stdio(0);

    int n, m, k;
    cin >> n >> m >> k;
    int p[n+5]={}, sum=0;
    bool f=0;
    for(int i = 2;i <= n;i++) 
    {
        cin>> p[i];
        adj[i].pb(p[i]);
        adj[p[i]].pb(i);
        if(p[i]!=i-1) f=1;
    }
    vector<int> s;
    for(int i = 0;i < m;i++) 
    {
        int v, d, w;
        cin >> v >> d >> w;
        s.pb(d);
        a[v]=d;
        fa[v]=w;
        sum+=w;
    }
    sort(all(s));
    s.erase(unique(all(s)),s.end());
    mxd=sz(s);
    for(int i = 1;i <= n;i++) 
    {
        if(a[i]==0) continue;
        a[i]=lower_bound(all(s), a[i])-s.begin()+1;
    }
    if(mxd<=1000) 
    {
        init(1);
        int ans=0;
        for(int i = 0;i <= mxd;i++) ans=max(ans, dp[1][i]);
        cout << ans;
        return 0;
    }
    if(f) {cout << sum;return 0;}
    vector<int> v;
    for(int i = n;i>=1;i--) 
    {
        if(a[i]==0) continue;
        auto it=upper_bound(all(v), a[i]);
        if(it==v.end()) v.pb(a[i]);
        else *it=a[i];
    }
    cout << sz(v);
}   
    

Compilation message (stderr)

magictree.cpp:31:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   31 | main()
      | ^~~~
/tmp/ccJbwDHy.o: in function `init(long long, long long)':
magictree.cpp:(.text+0x569): relocation truncated to fit: R_X86_64_PC32 against symbol `a' defined in .bss section in /tmp/ccJbwDHy.o
magictree.cpp:(.text+0x570): relocation truncated to fit: R_X86_64_PC32 against symbol `fa' defined in .bss section in /tmp/ccJbwDHy.o
/tmp/ccJbwDHy.o: in function `main':
magictree.cpp:(.text.startup+0x33): relocation truncated to fit: R_X86_64_PC32 against symbol `std::cin' defined in .bss._ZSt3cin section in /usr/lib/gcc/x86_64-linux-gnu/13/libstdc++.a(globals_io.o)
magictree.cpp:(.text.startup+0x4a): relocation truncated to fit: R_X86_64_PC32 against symbol `std::cin' defined in .bss._ZSt3cin section in /usr/lib/gcc/x86_64-linux-gnu/13/libstdc++.a(globals_io.o)
magictree.cpp:(.text.startup+0x184): relocation truncated to fit: R_X86_64_PC32 against symbol `std::cin' defined in .bss._ZSt3cin section in /usr/lib/gcc/x86_64-linux-gnu/13/libstdc++.a(globals_io.o)
magictree.cpp:(.text.startup+0x317): relocation truncated to fit: R_X86_64_PC32 against symbol `a' defined in .bss section in /tmp/ccJbwDHy.o
magictree.cpp:(.text.startup+0x32a): relocation truncated to fit: R_X86_64_PC32 against symbol `fa' defined in .bss section in /tmp/ccJbwDHy.o
magictree.cpp:(.text.startup+0x34c): relocation truncated to fit: R_X86_64_PC32 against symbol `std::cin' defined in .bss._ZSt3cin section in /usr/lib/gcc/x86_64-linux-gnu/13/libstdc++.a(globals_io.o)
magictree.cpp:(.text.startup+0x512): relocation truncated to fit: R_X86_64_PC32 against symbol `a' defined in .bss section in /tmp/ccJbwDHy.o
magictree.cpp:(.text.startup+0x61f): relocation truncated to fit: R_X86_64_PC32 against symbol `std::cout' defined in .bss._ZSt4cout section in /usr/lib/gcc/x86_64-linux-gnu/13/libstdc++.a(globals_io.o)
magictree.cpp:(.text.startup+0x98e): additional relocation overflows omitted from the output
/usr/lib/gcc/x86_64-linux-gnu/13/libstdc++.a(ios_init.o): in function `std::ios_base::Init::Init()':
(.text._ZNSt8ios_base4InitC2Ev+0x1f): failed to convert GOTPCREL relocation against '_ZNSt8ios_base4Init11_S_refcountE'; relink with --no-relax
(.text._ZNSt8ios_base4InitC2Ev+0x1ed): failed to convert GOTPCREL relocation against '_ZSt4cout'; relink with --no-relax
(.text._ZNSt8ios_base4InitC2Ev+0x252): failed to convert GOTPCREL relocation against '_ZSt3cin'; relink with --no-relax
(.text._ZNSt8ios_base4InitC2Ev+0x2bc): failed to convert GOTPCREL relocation against '_ZSt4cerr'; relink with --no-relax
(.text._ZNSt8ios_base4InitC2Ev+0x316): failed to convert GOTPCREL relocation against '_ZSt4clog'; relink with --no-relax
(.text._ZNSt8ios_base4InitC2Ev+0x50f): failed to convert GOTPCREL relocation against '_ZSt5wcout'; relink with --no-relax
(.text._ZNSt8ios_base4InitC2Ev+0x57d): failed to convert GOTPCREL relocation against '_ZSt4wcin'; relink with --no-relax
(.text._ZNSt8ios_base4InitC2Ev+0x5f0): failed to convert GOTPCREL relocation against '_ZSt5wcerr'; relink with --no-relax
(.text._ZNSt8ios_base4InitC2Ev+0x654): failed to convert GOTPCREL relocation against '_ZSt5wclog'; relink with --no-relax
/usr/bin/ld: final link failed
collect2: error: ld returned 1 exit status