Submission #404904

# Submission time Handle Problem Language Result Execution time Memory
404904 2021-05-15T09:25:55 Z Theo830 Dreaming (IOI13_dreaming) C++17
0 / 100
48 ms 12484 KB
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
typedef unsigned long long ull;
ll INF = 1e9+7;
ll MOD = 998244353;
typedef pair<ll,ll> ii;
#define iii pair<ll,ii>
#define f(i,a,b) for(ll i = a;i < b;i++)
#define pb push_back
#define vll vector<ll>
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
///I hope I will get uprating and don't make mistakes
///I will never stop programming
///sqrt(-1) Love C++
///Please don't hack me
///@TheofanisOrfanou Theo830
///Think different approaches (bs,dp,greedy,graphs,shortest paths,mst)
///Stay Calm
///Look for special cases
///Beware of overflow and array bounds
///Think the problem backwards
///Training
#include "dreaming.h"
int res = 0;
ll dp[100005];
ll subtree[100005];
ll pos = 0;
vector<vector<ii> >adj;
ll solve(ll x,ll p){
    if(dp[x] != -1){
        return dp[x];
    }
    subtree[x] = pos;
    ll ans = 0;
    for(auto y:adj[x]){
        if(y.F != p){
            ans = max(ans,y.S + solve(y.F,x));
        }
    }
    res = max(res,ans);
    return dp[x] = ans;
}
int travelTime(int n, int m, int L, int A[], int B[], int T[]) {
    adj.assign(n+5,vector<ii>());
    f(i,0,m){
        adj[A[i]].pb(ii(B[i],T[i]));
        adj[B[i]].pb(ii(A[i],T[i]));
    }
    memset(dp,-1,sizeof dp);
    ll pos = 0;
    f(i,1,n+1){
        if(dp[i] == -1){
            solve(i,0);
            pos++;
        }
    }
    ll mini[pos];
    f(i,0,pos){
        mini[i] = 1e9+7;
    }
    f(i,1,n+1){
        mini[subtree[i]] = min(mini[subtree[i]],dp[i]);
    }
    sort(mini,mini+pos);
    if(pos >= 2){
        res = max(res,mini[pos-1] + mini[pos-2] + L);
    }
    if(pos >= 3){
        res = max(res,mini[pos-3] + mini[pos-2] + 2 * L);
    }
    return res;
}
# Verdict Execution time Memory Grader output
1 Incorrect 48 ms 12484 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 588 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 48 ms 12484 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 21 ms 5720 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 588 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 48 ms 12484 KB Output isn't correct
2 Halted 0 ms 0 KB -