답안 #968142

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
968142 2024-04-23T07:56:59 Z Hugo1729 꿈 (IOI13_dreaming) C++11
18 / 100
50 ms 12324 KB
#include <bits/stdc++.h>
#include "dreaming.h"
using namespace std;
#define f first
#define s second

vector<pair<int,int>> adj[100000];

int dp1[100000],dp2[100000],dp3[100000];
bool marked[100000]={0};

int dfs_sizes1(int v, int pV){
    dp1[v]=0;
    dp2[v]=0;
    marked[v]=1;
    for(auto [w,d] : adj[v]){
        if(w!=pV){
            int sus=dfs_sizes1(w,v)+d;
            if(sus>dp1[v]){
                dp2[v]=dp1[v];
                dp1[v]=sus;
            }else if(sus>dp2[v]){
                dp2[v]=sus;
            }
        }
    }
    return dp1[v];
}

void dfs_sizes2(int v, int pV){
    for(auto [w,d] : adj[v]){
        if(w!=pV){
            if(dp1[w]+d==dp1[v]){
                dp3[w]=max(dp2[v],dp3[v])+d;
            }else{
                dp3[w]=max(dp1[v],dp3[v])+d;
            }
            dfs_sizes2(w,v);
        }
    }
}

int dfs_final(int v, int pV){
    int ans=max(dp1[v],dp3[v]);

    for(auto [w,d] : adj[v]){
        if(w!=pV){
            ans=min(ans,dfs_final(w,v));
        }
    }

    return ans;
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
    for(int i=0;i<M;i++){
        adj[A[i]].push_back({B[i],T[i]});
        adj[B[i]].push_back({A[i],T[i]});
    }

    vector<int> sussy;

    for(int i=0;i<N;i++){
        if(!marked[i]){
            dfs_sizes1(i,i);
            dfs_sizes2(i,i);
            sussy.push_back(-dfs_final(i,i));
            // cout <<i << ' ' << sussy[sussy.size()-1] << '\n';
        }

        // cout << i << ' ' << dp1[i].first << ' ' << dp1[i].second << '\n';

    }

    for(int i=0;i<N;i++){
        // cout << i << ' ' << dp1[i] << ' ' << dp2[i] << ' ' << dp3[i] << '\n';
    }

    sort(sussy.begin(),sussy.end());

    if(sussy.size()==1)return -sussy[0];
    else if(sussy.size()==2)return -sussy[0]-sussy[1]+L;

    return max(-sussy[0]-sussy[1]+L,-sussy[2]-sussy[1]+L*2);
}

Compilation message

dreaming.cpp: In function 'int dfs_sizes1(int, int)':
dreaming.cpp:16:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   16 |     for(auto [w,d] : adj[v]){
      |              ^
dreaming.cpp: In function 'void dfs_sizes2(int, int)':
dreaming.cpp:31:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   31 |     for(auto [w,d] : adj[v]){
      |              ^
dreaming.cpp: In function 'int dfs_final(int, int)':
dreaming.cpp:46:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   46 |     for(auto [w,d] : adj[v]){
      |              ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 50 ms 12324 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 4956 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 50 ms 12324 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 7432 KB Output is correct
2 Correct 14 ms 7516 KB Output is correct
3 Correct 16 ms 7512 KB Output is correct
4 Correct 14 ms 7512 KB Output is correct
5 Correct 17 ms 7516 KB Output is correct
6 Correct 20 ms 7904 KB Output is correct
7 Correct 20 ms 7568 KB Output is correct
8 Correct 13 ms 7392 KB Output is correct
9 Correct 20 ms 7384 KB Output is correct
10 Correct 20 ms 7768 KB Output is correct
11 Correct 1 ms 4956 KB Output is correct
12 Correct 6 ms 5592 KB Output is correct
13 Correct 4 ms 5592 KB Output is correct
14 Correct 4 ms 5592 KB Output is correct
15 Correct 4 ms 5592 KB Output is correct
16 Correct 3 ms 5592 KB Output is correct
17 Correct 3 ms 5592 KB Output is correct
18 Correct 4 ms 5592 KB Output is correct
19 Correct 6 ms 5604 KB Output is correct
20 Correct 1 ms 2908 KB Output is correct
21 Correct 1 ms 2908 KB Output is correct
22 Correct 1 ms 5208 KB Output is correct
23 Correct 4 ms 5592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 4956 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 50 ms 12324 KB Output isn't correct
2 Halted 0 ms 0 KB -