답안 #794698

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
794698 2023-07-26T19:16:28 Z Khizri 꿈 (IOI13_dreaming) C++17
18 / 100
42 ms 15612 KB
#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
#define INF 1e18
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pii pair<int,int>
#define pll pair<ll,ll>
#define OK cout<<"Ok"<<endl;
#define MOD (ll)(1e9+7)
const int mxn=1e5+5;
int n,m,color[mxn],mx,node,node2,res,l[mxn];
vector<pii>vt[mxn];
pii back[mxn];
void dfs(int u,int p,int dis){
    if(dis>=mx){
        mx=dis;
        node=u;
    }
    color[u]=1;
    for(pii v:vt[u]){
        if(v.F!=p){
            dfs(v.F,u,dis+v.S);
        }
    }
}
void dfs2(int u,int p,int dis){
    l[u]=dis;
    if(dis>=mx){
        mx=dis;
        node2=u;
    }
    for(pii v:vt[u]){
        if(v.F!=p){
            dfs2(v.F,u,dis+v.S);
            back[v.F].F=u;
            back[v.F].S=v.S;
        }
    }
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
    n=N,m=M;
    for(int i=0;i<m;i++){
        vt[A[i]+1].pb({B[i]+1,T[i]});
        vt[B[i]+1].pb({A[i]+1,T[i]});
    }
    vector<int>vtt;
    for(int i=1;i<=n;i++){
        if(color[i]) continue;
        mx=0,node=0;
        dfs(i,-1,0);
        mx=0,node2=0;
        dfs2(node,-1,0);
        res=2e9;
        back[node].F=0;
        int sum=0;
        while(back[node2].F!=0){
            res=min(res,max(sum,l[node2]));
            sum+=back[node2].S;
            node2=back[node2].F;
        }
        res=min(res,max(sum,l[node2]));
        vtt.pb(res);
    }
    sort(rall(vtt));
    if(vtt.size()==1) return vtt[0];
    int ans=vtt[0]+vtt[1]+L;
    if(vtt.size()>2){
        ans=max(ans,vtt[1]+vtt[2]+2*L);
    }
    return ans;
}
/*
12 8 2
0 8 4
8 2 2 
2 7 4
5 11 3
5 1 7
1 3 1
1 9 5
10 6 3
 
6 5 3
0 1 2
1 2 1
2 3 2
3 4 1
4 5 0
*/
# 결과 실행 시간 메모리 Grader output
1 Incorrect 42 ms 15612 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 42 ms 15612 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 7176 KB Output is correct
2 Correct 15 ms 7276 KB Output is correct
3 Correct 14 ms 7256 KB Output is correct
4 Correct 14 ms 7284 KB Output is correct
5 Correct 13 ms 7252 KB Output is correct
6 Correct 15 ms 7788 KB Output is correct
7 Correct 14 ms 7480 KB Output is correct
8 Correct 14 ms 7156 KB Output is correct
9 Correct 14 ms 7124 KB Output is correct
10 Correct 14 ms 7380 KB Output is correct
11 Correct 2 ms 2644 KB Output is correct
12 Correct 6 ms 4912 KB Output is correct
13 Correct 4 ms 4816 KB Output is correct
14 Correct 4 ms 4816 KB Output is correct
15 Correct 4 ms 4816 KB Output is correct
16 Correct 4 ms 4816 KB Output is correct
17 Correct 4 ms 4684 KB Output is correct
18 Correct 6 ms 4844 KB Output is correct
19 Correct 4 ms 4816 KB Output is correct
20 Correct 2 ms 2668 KB Output is correct
21 Correct 1 ms 2644 KB Output is correct
22 Correct 2 ms 2644 KB Output is correct
23 Correct 4 ms 4816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 42 ms 15612 KB Output isn't correct
2 Halted 0 ms 0 KB -