Submission #218914

# Submission time Handle Problem Language Result Execution time Memory
218914 2020-04-03T06:50:21 Z KoalaMuch Dreaming (IOI13_dreaming) C++14
0 / 100
58 ms 11768 KB
#include "dreaming.h"
//#include "grader.cpp"
#include<bits/stdc++.h>
using namespace std;
const int MxN = 1e5+5;
vector< pair< int,int > > g[MxN];
bool mark[MxN];
int ans;
int dp[MxN][2];
int all[MxN];
void dfs(int u,int p = -1)
{
    mark[u] = 1;
    for(auto &x:g[u])
    {
        if(x.first==p)    continue;
        dfs(x.first,u);
        if(dp[x.first][0]+x.second>dp[u][0])   dp[u][0] = dp[x.first][0]+x.second;
        else if(dp[x.first][0]+x.second>dp[u][1])   dp[u][1] = dp[x.first][0]+x.second;
    }
}
int reroot(int u,int p = -1)
{
    int mn = 2e9;
    for(auto &x:g[u])
    {
        if(x.first==p)  continue;
        int nowv = x.second+dp[x.first][0];
        if(nowv==dp[u][0])  nowv = dp[u][1]+x.second;
        if(nowv>dp[x.first][0])   dp[x.first][0] = nowv;
        else if(nowv>dp[x.first][1])  dp[x.first][1] = nowv;
        mn = min(mn,reroot(x.first,u));
    }
    ans = max(ans,dp[u][0]+dp[u][1]);
    return min(mn,dp[u][0]);
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
    int n = 0;
    for(int i=0;i<M;i++)    g[A[i]].push_back({B[i],T[i]}),g[B[i]].push_back({A[i],T[i]});
    for(int i=0;i<N;i++)
    {
        if(!mark[i])
        {
            ++n;
            dfs(i);
            all[n] = reroot(i);
        }
    }
    sort(all+1,all+n+1);
    if(n>=2)    ans = max(ans,all[1]+all[2]+L);
    if(n>=3)    ans = max(ans,all[2]+all[3]+2*L);
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 57 ms 11768 KB Output is correct
2 Incorrect 58 ms 11512 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 57 ms 11768 KB Output is correct
2 Incorrect 58 ms 11512 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 57 ms 11768 KB Output is correct
2 Incorrect 58 ms 11512 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 27 ms 6528 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 57 ms 11768 KB Output is correct
2 Incorrect 58 ms 11512 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 57 ms 11768 KB Output is correct
2 Incorrect 58 ms 11512 KB Output isn't correct
3 Halted 0 ms 0 KB -