답안 #794617

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
794617 2023-07-26T16:32:21 Z Khizri 꿈 (IOI13_dreaming) C++17
18 / 100
39 ms 14408 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];
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);
        }
    }
}
bool dfs3(int u,int p,int dis){
    int q=0;
    if(u==node) q=1;
    for(pii v:vt[u]){
        if(v.F!=p&&dfs3(v.F,u,dis+v.S)){
            q=1;
            res=min(res,max(l[v.F],dis+v.S));
        }
    }
    return q;
}
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=mx;
        dfs3(node2,-1,0);
        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

7 5 3
0 1 2
1 2 2
2 3 4
4 5 5 
5 6 6 
*/
# 결과 실행 시간 메모리 Grader output
1 Incorrect 39 ms 14408 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 39 ms 14408 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 6104 KB Output is correct
2 Correct 15 ms 6140 KB Output is correct
3 Correct 14 ms 6488 KB Output is correct
4 Correct 14 ms 6484 KB Output is correct
5 Correct 14 ms 6484 KB Output is correct
6 Correct 15 ms 6960 KB Output is correct
7 Correct 15 ms 6632 KB Output is correct
8 Correct 18 ms 6432 KB Output is correct
9 Correct 14 ms 6396 KB Output is correct
10 Correct 15 ms 6644 KB Output is correct
11 Correct 1 ms 2644 KB Output is correct
12 Correct 4 ms 4048 KB Output is correct
13 Correct 4 ms 4048 KB Output is correct
14 Correct 6 ms 4064 KB Output is correct
15 Correct 4 ms 4048 KB Output is correct
16 Correct 5 ms 4048 KB Output is correct
17 Correct 4 ms 3920 KB Output is correct
18 Correct 4 ms 4048 KB Output is correct
19 Correct 4 ms 4048 KB Output is correct
20 Correct 3 ms 2644 KB Output is correct
21 Correct 1 ms 2568 KB Output is correct
22 Correct 2 ms 2664 KB Output is correct
23 Correct 4 ms 4048 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 39 ms 14408 KB Output isn't correct
2 Halted 0 ms 0 KB -