답안 #900567

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
900567 2024-01-08T14:38:57 Z JakobZorz 꿈 (IOI13_dreaming) C++17
0 / 100
18 ms 5076 KB
#include"dreaming.h"
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;
typedef long long ll;

vector<pair<ll,ll>>nodes[100000];
bool vis[100000];
vector<ll>node_list;

void dfs(ll node){
    if(vis[node])
        return;
    vis[node]=true;
    node_list.push_back(node);
    for(auto ne:nodes[node])
        dfs(ne.first);
}

map<pair<ll,ll>,ll>dp;
ll get_max_dist(ll node,ll prev){
    if(dp.count({node,prev}))
        return dp[{node,prev}];
    
    ll res=0;
    for(auto ne:nodes[node]){
        if(ne.first==prev)
            continue;
        res=max(res,get_max_dist(ne.first,node)+ne.second);
    }
    dp[{node,prev}]=res;
    return res;
}

ll get_diameter(ll root){
    node_list.clear();
    dfs(root);
    /*cout<<"- ";
    for(int i:node_list)
        cout<<i<<" ";
    cout<<"\n";*/
    
    ll res=1e18;
    for(ll node:node_list){
        //cout<<node<<": "<<get_max_dist(node,node)<<"\n";
        res=min(res,get_max_dist(node,node));
    }
    return res;
}

int travelTime(int N,int M,int L,int A[],int B[],int T[]){
    vector<ll>dists;
    for(int i=0;i<M;i++)
        dists.push_back(T[i]);
    sort(dists.begin(),dists.end());
    reverse(dists.begin(),dists.end());
    if(dists.size()==1)
        return dists[0];
    else
        return dists[0]+dists[1]+L;
    
    /*for(ll i=0;i<M;i++){
        nodes[A[i]].emplace_back(B[i],T[i]);
        nodes[B[i]].emplace_back(A[i],T[i]);
    }
    
    vector<ll>dists;
    for(ll i=0;i<N;i++)
        if(!vis[i])
            dists.push_back(get_diameter(i));
    
    sort(dists.begin(),dists.end());
    reverse(dists.begin(),dists.end());
    if(dists.size()==1)
        return dists[0];
    else
        return dists[0]+dists[1]+L;*/
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 18 ms 5076 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 3676 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 18 ms 5076 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 4308 KB Output is correct
2 Incorrect 7 ms 4308 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 3676 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 18 ms 5076 KB Output isn't correct
2 Halted 0 ms 0 KB -