답안 #1015479

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1015479 2024-07-06T11:28:58 Z lalig777 꿈 (IOI13_dreaming) C++14
18 / 100
28 ms 11612 KB
#include "dreaming.h"
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int ll;
 
vector<vector<pair<int, int>>> g;
vector<bool>used;
vector<int>ans;
vector<pair<int, int>>dp;
int res=2e9;
 
void dfs1(int u){
  used[u]=true;
  for(pair<int, int> vec:g[u]){
    int v=vec.first, c=vec.second;
    if (used[v]) continue;
    dfs1(v);
    if (dp[u].first<dp[v].first+c){
      dp[u].second=dp[u].first;
      dp[u].first=dp[v].first+c;
    }else if (dp[u].second<dp[v].first+c){
      dp[u].second=dp[v].first+c;
    }
  }return;
}
 
void dfs2(int u, int p, int maxi){
  int maxim=maxi;
  res=min(res, max(maxim,dp[u].first));
  for(pair<int, int> vec:g[u]){
    int v=vec.first, c=vec.second;
    if (v==p) continue;
    if (dp[u].first==dp[v].first+c) maxi=max(maxim+c, dp[u].second+c);
    else maxi=max(maxim, dp[u].first+c);
    dfs2(v, u, maxi);
  }return;
}
 
int travelTime(int N, int M, int L, int A[], int B[], int T[]){
  g.resize(N);
  used.assign(N, false);
  dp.assign(N, {0, 0});
  for (int i=0; i<M; i++){
    g[A[i]].push_back({B[i], T[i]});
    g[B[i]].push_back({A[i], T[i]});
  }for (int i=0; i<N; i++){
    if (used[i]) continue;
    res=2e9;
    dfs1(i);
    dfs2(i, -1, 0);
    ans.push_back(res);
  }sort(ans.begin(), ans.end());
  reverse(ans.begin(), ans.end());
  if (ans.size()==1) return ans[0];
  if (ans.size()==2) return ans[0]+ans[1]+L;
  return max(ans[0]+ans[1]+L, ans[1]+ans[2]+2*L);
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 28 ms 11612 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 28 ms 11612 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 6492 KB Output is correct
2 Correct 17 ms 6544 KB Output is correct
3 Correct 13 ms 6492 KB Output is correct
4 Correct 11 ms 6488 KB Output is correct
5 Correct 19 ms 6468 KB Output is correct
6 Correct 13 ms 7132 KB Output is correct
7 Correct 16 ms 6780 KB Output is correct
8 Correct 17 ms 6332 KB Output is correct
9 Correct 12 ms 6368 KB Output is correct
10 Correct 13 ms 6748 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 4 ms 4052 KB Output is correct
13 Correct 5 ms 4056 KB Output is correct
14 Correct 5 ms 4056 KB Output is correct
15 Correct 3 ms 4040 KB Output is correct
16 Correct 3 ms 4056 KB Output is correct
17 Correct 3 ms 4056 KB Output is correct
18 Correct 4 ms 4312 KB Output is correct
19 Correct 4 ms 4056 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 4 ms 4116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 28 ms 11612 KB Output isn't correct
2 Halted 0 ms 0 KB -