Submission #718571

# Submission time Handle Problem Language Result Execution time Memory
718571 2023-04-04T10:50:07 Z ovidiush11 Dreaming (IOI13_dreaming) C++14
18 / 100
41 ms 14540 KB
#include <bits/stdc++.h>
#include "dreaming.h"

using namespace std;

#define ll long long
#define ff first
#define ss second
#define mp make_pair

const ll N_ = 1e5+7;

vector<vector<pair<ll,ll>>> a;
vector<ll> maxdistree;
bool st[N_];
pair<ll,ll> disn[N_];

ll maketree(ll p)
{
    st[p] = 1;
    ll x = 0,y = 0;
    for(auto v : a[p])
    {
        if(st[v.ss])continue;
        ll k = maketree(v.ss) + v.ff;
        if(k > x){y = x;x = k;}
        else if(k > y)y = k;
    }
    disn[p].ff = x;
    disn[p].ss = y;
    return x;
}

ll maxtree(ll p,ll k,ll ans)
{
    if(k > ans)return ans;
    k = max(k,disn[p].ss);
    ans = max(disn[p].ff,k);
    ll to = -1;
    for(auto v : a[p])
    {
        if(v.ff + disn[v.ss].ff == disn[p].ff)
        {
            to = v.ss;
            k += v.ff;
            break;
        }
    }
    if(to == -1)return ans;
    return maxtree(to,k,ans);
}

ll solvefor1(ll n)
{
    ll ans = 0;
    for(ll i = 0;i < n;i++)ans = max(ans,disn[i].ff + disn[i].ss);
    return ans;
}

int travelTime(int N, int M, int L, int A[], int B[], int T[])
{
    a.resize(N);
    for(ll i = 0;i < M;i++)
    {
        a[A[i]].push_back(mp(T[i],B[i]));
        a[B[i]].push_back(mp(T[i],A[i]));
    }
    for(ll i = 0;i < N;i++)st[i] = 0;
    for(ll i = 0;i < N;i++)
    {
        if(!st[i]){
            maketree(i);
            ll x = maxtree(i,0,1e18);
            maxdistree.push_back(x);
        }
    }
    sort(maxdistree.begin(),maxdistree.end(),greater<int>());
    if(maxdistree.size() == 1)return solvefor1(N);
    if(maxdistree.size() == 2)return maxdistree[0] + maxdistree[1] + L;
    return max(maxdistree[0] + maxdistree[1] + L,maxdistree[2] + maxdistree[1] + 2 * L);
}
# Verdict Execution time Memory Grader output
1 Incorrect 41 ms 14540 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 41 ms 14540 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 22 ms 7364 KB Output is correct
2 Correct 19 ms 7432 KB Output is correct
3 Correct 18 ms 7384 KB Output is correct
4 Correct 18 ms 7432 KB Output is correct
5 Correct 20 ms 7448 KB Output is correct
6 Correct 25 ms 8320 KB Output is correct
7 Correct 21 ms 7752 KB Output is correct
8 Correct 20 ms 7256 KB Output is correct
9 Correct 18 ms 7248 KB Output is correct
10 Correct 21 ms 7688 KB Output is correct
11 Correct 1 ms 308 KB Output is correct
12 Correct 5 ms 5292 KB Output is correct
13 Correct 5 ms 5452 KB Output is correct
14 Correct 5 ms 5196 KB Output is correct
15 Correct 5 ms 5296 KB Output is correct
16 Correct 6 ms 5196 KB Output is correct
17 Correct 7 ms 5256 KB Output is correct
18 Correct 5 ms 5452 KB Output is correct
19 Correct 6 ms 5160 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 1 ms 432 KB Output is correct
23 Correct 4 ms 5196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 41 ms 14540 KB Output isn't correct
2 Halted 0 ms 0 KB -