답안 #867589

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
867589 2023-10-28T20:12:14 Z dpsaveslives 꿈 (IOI13_dreaming) C++17
18 / 100
34 ms 7136 KB
#include "dreaming.h"
#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;
int n;
const int MAXN = 1e5+10;
bool visited[MAXN],visited2[MAXN];
vector<pair<int,int>> adj[MAXN];
pair<int,int> dijkstra(bool *vis, int src){
    pair<int,int> ret; ret.f = ret.s = -1;
    priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> pq;
    pq.push({0,src}); vis[src] = true;
    while(!pq.empty()){
        int u = pq.top().s, d = pq.top().f; pq.pop(); 
        if(ret.f < d){
            ret.f = d;
            ret.s = u;
        }
        for(auto p : adj[u]){
            if(!vis[p.f]){
                vis[p.f] = true;
                pq.push({d+p.s,p.f});
            }
        }
    }
    return ret;
}
 
int longpath(int u){
    int a = dijkstra(visited2,u).s;
    return dijkstra(visited,a).f;
}
int res = 0, l;
bool dfs(int curu, int p, int tar, int d){
  	if(curu == tar) return true; 
    for(auto x : adj[curu]){
        if(x.f != p){
            if(dfs(x.f,curu,tar,d+x.s)){
                res = min(res,max(d,l-d));
                return true;
            }
        }
    }
    return false;
}
int calc(int u){
    int a = dijkstra(visited2,u).s;
    pair<int,int> val = dijkstra(visited,u);
    int b = val.s;
    res = val.f; l = val.f;
    dfs(a,-1,b,0);
    return res;
}
int travelTime(int N,int M,int L,int A[],int B[],int T[]){
    n = N;
    for(int i = 0;i<M;++i){
        int u = A[i],v = B[i],w = T[i];
        adj[u].push_back({v,w}); adj[v].push_back({u,w});
    }
    int ans = 0;
    for(int i = 0;i<N;++i){
        if(!visited[i]){
            ans = max(ans,longpath(i));
        }
    }
    memset(visited,false,sizeof(visited)); memset(visited2,false,sizeof(visited2));
    vector<int> results;
    for(int i = 0;i<N;++i){
        if(!visited[i]){
            results.push_back(calc(i));
        }
    }
    sort(results.rbegin(),results.rend());
    if(results.size() > 1){
        ans =max(ans,results[0]+results[1]+L);
    }
    if(results.size() > 2){
        ans = max(ans,results[1]+results[2]+2*L);
    }
    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 7004 KB Output is correct
2 Correct 33 ms 7000 KB Output is correct
3 Correct 23 ms 5980 KB Output is correct
4 Correct 6 ms 4444 KB Output is correct
5 Correct 5 ms 4340 KB Output is correct
6 Correct 9 ms 4444 KB Output is correct
7 Incorrect 1 ms 3928 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 3928 KB Output is correct
2 Incorrect 1 ms 3932 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 7004 KB Output is correct
2 Correct 33 ms 7000 KB Output is correct
3 Correct 23 ms 5980 KB Output is correct
4 Correct 6 ms 4444 KB Output is correct
5 Correct 5 ms 4340 KB Output is correct
6 Correct 9 ms 4444 KB Output is correct
7 Incorrect 1 ms 3928 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 6368 KB Output is correct
2 Correct 23 ms 6776 KB Output is correct
3 Correct 22 ms 6748 KB Output is correct
4 Correct 23 ms 6872 KB Output is correct
5 Correct 22 ms 6748 KB Output is correct
6 Correct 25 ms 7136 KB Output is correct
7 Correct 24 ms 6932 KB Output is correct
8 Correct 22 ms 6748 KB Output is correct
9 Correct 23 ms 6712 KB Output is correct
10 Correct 26 ms 6876 KB Output is correct
11 Correct 1 ms 3932 KB Output is correct
12 Correct 13 ms 4568 KB Output is correct
13 Correct 14 ms 4568 KB Output is correct
14 Correct 14 ms 4516 KB Output is correct
15 Correct 13 ms 4568 KB Output is correct
16 Correct 13 ms 4564 KB Output is correct
17 Correct 13 ms 4568 KB Output is correct
18 Correct 13 ms 4568 KB Output is correct
19 Correct 13 ms 4568 KB Output is correct
20 Correct 1 ms 3932 KB Output is correct
21 Correct 1 ms 4184 KB Output is correct
22 Correct 1 ms 3932 KB Output is correct
23 Correct 13 ms 4584 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 3928 KB Output is correct
2 Incorrect 1 ms 3932 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 7004 KB Output is correct
2 Correct 33 ms 7000 KB Output is correct
3 Correct 23 ms 5980 KB Output is correct
4 Correct 6 ms 4444 KB Output is correct
5 Correct 5 ms 4340 KB Output is correct
6 Correct 9 ms 4444 KB Output is correct
7 Incorrect 1 ms 3928 KB Output isn't correct
8 Halted 0 ms 0 KB -