답안 #218915

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
218915 2020-04-03T06:53:56 Z KoalaMuch 꿈 (IOI13_dreaming) C++14
0 / 100
57 ms 10488 KB
#include "dreaming.h"
#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[u][0];
        if(x.second+dp[x.first][0]==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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 57 ms 10488 KB Output is correct
2 Correct 56 ms 10360 KB Output is correct
3 Correct 42 ms 9976 KB Output is correct
4 Correct 13 ms 4096 KB Output is correct
5 Correct 12 ms 3584 KB Output is correct
6 Correct 18 ms 4736 KB Output is correct
7 Incorrect 6 ms 2688 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 57 ms 10488 KB Output is correct
2 Correct 56 ms 10360 KB Output is correct
3 Correct 42 ms 9976 KB Output is correct
4 Correct 13 ms 4096 KB Output is correct
5 Correct 12 ms 3584 KB Output is correct
6 Correct 18 ms 4736 KB Output is correct
7 Incorrect 6 ms 2688 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 57 ms 10488 KB Output is correct
2 Correct 56 ms 10360 KB Output is correct
3 Correct 42 ms 9976 KB Output is correct
4 Correct 13 ms 4096 KB Output is correct
5 Correct 12 ms 3584 KB Output is correct
6 Correct 18 ms 4736 KB Output is correct
7 Incorrect 6 ms 2688 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 30 ms 6016 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 57 ms 10488 KB Output is correct
2 Correct 56 ms 10360 KB Output is correct
3 Correct 42 ms 9976 KB Output is correct
4 Correct 13 ms 4096 KB Output is correct
5 Correct 12 ms 3584 KB Output is correct
6 Correct 18 ms 4736 KB Output is correct
7 Incorrect 6 ms 2688 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 57 ms 10488 KB Output is correct
2 Correct 56 ms 10360 KB Output is correct
3 Correct 42 ms 9976 KB Output is correct
4 Correct 13 ms 4096 KB Output is correct
5 Correct 12 ms 3584 KB Output is correct
6 Correct 18 ms 4736 KB Output is correct
7 Incorrect 6 ms 2688 KB Output isn't correct
8 Halted 0 ms 0 KB -