답안 #469936

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
469936 2021-09-02T11:13:33 Z Newtech66 꿈 (IOI13_dreaming) C++17
18 / 100
68 ms 14916 KB
#include "dreaming.h"
#include<bits/stdc++.h>
using namespace std;
using lol=long long int;

void dfs(int u,const vector<vector<pair<int,int> > >& g,vector<int>& vis,vector<int>& D,vector<int>& sD,vector<int>& marked)
{
    vis[u]=1;
    for(auto [v,w]:g[u])
    {
        if(vis[v]==1)  continue;
        dfs(v,g,vis,D,sD,marked);
        if(D[v]+w>=D[u])
        {
            sD[u]=D[u];
            D[u]=D[v]+w;
            marked[u]=v;
        }else if(D[v]+w>=sD[u])
        {
            sD[u]=D[v]+w;
        }
    }
}

void reroot(int u,const vector<vector<pair<int,int> > >& g,vector<int>& vis,vector<int>& D,vector<int>& sD,vector<int>& marked,vector<int>& fD)
{
    vis[u]=2;
    for(auto [v,w]:g[u])
    {
        if(vis[v]==2)   continue;
        if(v!=marked[u])
        {
            if(fD[u]+w>=D[v])
            {
                sD[v]=fD[v];
                fD[v]=fD[u]+w;
                marked[v]=u;
            }else if(fD[u]+w>=sD[v])
            {
                fD[v]=D[v];
                sD[v]=fD[u]+w;
            }
        }else
        {
            if(sD[u]+w>=D[v])
            {
                sD[v]=fD[v];
                fD[v]=sD[u]+w;
                marked[v]=u;
            }else if(sD[u]+w>=sD[v])
            {
                fD[v]=D[v];
                sD[v]=sD[u]+w;
            }
        }
        reroot(v,g,vis,D,sD,marked,fD);
    }
}

int getrep(int u,const vector<vector<pair<int,int> > >& g,vector<int>& vis,const vector<int>& fD)
{
    vis[u]=3;
    int mn=fD[u];
    for(auto [v,w]:g[u])
    {
        if(vis[v]==3)   continue;
        mn=min(mn,getrep(v,g,vis,fD));
    }
    return mn;
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
    vector<vector<pair<int,int> > > g(N);
    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]});
    }
    vector<int> D(N,0),sD(N,0),fD(N,0),marked(N,-1);
    vector<int> vis(N,0);
    vector<int> reps;
    for(int i=0;i<N;i++)
    {
        if(vis[i]==0)
        {
            dfs(i,g,vis,D,sD,marked);
            fD[i]=D[i];
            reroot(i,g,vis,D,sD,marked,fD);
            reps.push_back(getrep(i,g,vis,fD));
        }
    }
    sort(reps.rbegin(),reps.rend());
    /*for(auto& e:D)  cout<<e<<" ";
    cout<<endl;
    for(auto& e:sD)  cout<<e<<" ";
    cout<<endl;
    for(auto& e:fD) cout<<e<<" ";
    cout<<endl;
    for(auto& e:reps)   cout<<e<<" ";
    cout<<endl;*/
    int ans=reps[0];
    if(reps.size()>1)    ans=max(ans,L+reps[0]+reps[1]);
    if(reps.size()>2)    ans=max(ans,2*L+reps[1]+reps[2]);
    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 68 ms 14916 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 68 ms 14916 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 7396 KB Output is correct
2 Correct 38 ms 7492 KB Output is correct
3 Correct 31 ms 7388 KB Output is correct
4 Correct 30 ms 7384 KB Output is correct
5 Correct 27 ms 7396 KB Output is correct
6 Correct 31 ms 8064 KB Output is correct
7 Correct 37 ms 7696 KB Output is correct
8 Correct 28 ms 7336 KB Output is correct
9 Correct 30 ms 7304 KB Output is correct
10 Correct 32 ms 7676 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 7 ms 5192 KB Output is correct
13 Correct 7 ms 5320 KB Output is correct
14 Correct 7 ms 5192 KB Output is correct
15 Correct 9 ms 5192 KB Output is correct
16 Correct 7 ms 5192 KB Output is correct
17 Correct 7 ms 5192 KB Output is correct
18 Correct 7 ms 5320 KB Output is correct
19 Correct 7 ms 5192 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 460 KB Output is correct
23 Correct 7 ms 5192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 68 ms 14916 KB Output isn't correct
2 Halted 0 ms 0 KB -