답안 #469999

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
469999 2021-09-02T14:18:24 Z Newtech66 꿈 (IOI13_dreaming) C++17
32 / 100
101 ms 13668 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=max(reps[0],*max_element(fD.begin(),fD.end()));
    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 Correct 63 ms 13668 KB Output is correct
2 Correct 64 ms 13360 KB Output is correct
3 Correct 48 ms 11128 KB Output is correct
4 Correct 8 ms 2380 KB Output is correct
5 Correct 8 ms 1484 KB Output is correct
6 Correct 14 ms 3276 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 28 ms 5908 KB Output is correct
9 Correct 48 ms 9000 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 62 ms 10092 KB Output is correct
12 Correct 101 ms 11844 KB Output is correct
13 Correct 2 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 1 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 63 ms 13668 KB Output is correct
2 Correct 64 ms 13360 KB Output is correct
3 Correct 48 ms 11128 KB Output is correct
4 Correct 8 ms 2380 KB Output is correct
5 Correct 8 ms 1484 KB Output is correct
6 Correct 14 ms 3276 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 28 ms 5908 KB Output is correct
9 Correct 48 ms 9000 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 62 ms 10092 KB Output is correct
12 Correct 101 ms 11844 KB Output is correct
13 Correct 2 ms 332 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Incorrect 1 ms 204 KB Output isn't correct
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 6992 KB Output is correct
2 Correct 30 ms 7056 KB Output is correct
3 Correct 29 ms 7012 KB Output is correct
4 Correct 37 ms 7084 KB Output is correct
5 Correct 33 ms 6936 KB Output is correct
6 Correct 41 ms 7624 KB Output is correct
7 Correct 30 ms 7328 KB Output is correct
8 Correct 33 ms 6900 KB Output is correct
9 Correct 26 ms 6876 KB Output is correct
10 Correct 31 ms 7216 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 9 ms 5192 KB Output is correct
13 Correct 8 ms 5196 KB Output is correct
14 Correct 7 ms 5192 KB Output is correct
15 Correct 7 ms 5192 KB Output is correct
16 Correct 7 ms 5256 KB Output is correct
17 Correct 7 ms 5192 KB Output is correct
18 Correct 10 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 0 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 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 1 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 63 ms 13668 KB Output is correct
2 Correct 64 ms 13360 KB Output is correct
3 Correct 48 ms 11128 KB Output is correct
4 Correct 8 ms 2380 KB Output is correct
5 Correct 8 ms 1484 KB Output is correct
6 Correct 14 ms 3276 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 28 ms 5908 KB Output is correct
9 Correct 48 ms 9000 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 62 ms 10092 KB Output is correct
12 Correct 101 ms 11844 KB Output is correct
13 Correct 2 ms 332 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Incorrect 1 ms 204 KB Output isn't correct
17 Halted 0 ms 0 KB -