답안 #1003893

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1003893 2024-06-20T19:41:54 Z asdasdqwer 꿈 (IOI13_dreaming) C++14
18 / 100
29 ms 13268 KB
#include "dreaming.h"

#include <bits/stdc++.h>
using namespace std;

#define pii array<int,2>
vector<bool> vis;
vector<vector<pii>> g;

vector<int> nds;
vector<int> dis1, dis2;

void dfs1(int node, int parent, vector<int> &dis) {
  vis[node] = true;
  nds.push_back(node);

  for (auto [w, t] : g[node]) {
    if (w == parent) continue;
    dis[w] = dis[node] + t;
    dfs1(w, node, dis);
  }
}

int cmp(int start) {
  nds.clear();
  dis1[start] = 0;
  dfs1(start, -1, dis1);

  // find node with maximum distance
  int nd1 = nds[0];
  for (auto &x:nds) {
    if (dis1[x] > dis1[nd1]) nd1 = x;
  }

  dis1[nd1] = 0;
  nds.clear();
  dfs1(nd1, -1, dis1);

  int nd2 = nds[0];
  for (auto &x:nds) {
    if (dis1[x] > dis1[nd2]) nd2 = x;
  }

  nds.clear();
  dfs1(nd2, -1, dis2);

  int mnVal = 1e9;
  
  for (auto &x:nds) {
    mnVal = min(mnVal, max(dis1[x], dis2[x]));
  }
  return mnVal;
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
  vis.assign(N, false);
  dis1.assign(N, 0);
  dis2.assign(N, 0);
  g.resize(N);

  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]});
  }

  vector<int> vals;
  
  for (int i=0;i<N;i++) {
    if (vis[i]) continue;
    vals.push_back(cmp(i));
  }

  sort(vals.begin(), vals.end(), greater<int>());
  if (vals.size() == 1) return vals[0];
  if (vals.size() == 2) return vals[0] + vals[1] + L;
  return max(vals[0] + vals[1] + L, vals[1] + vals[2] + 2*L);
}

Compilation message

dreaming.cpp: In function 'void dfs1(int, int, std::vector<int>&)':
dreaming.cpp:17:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   17 |   for (auto [w, t] : g[node]) {
      |             ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 29 ms 13268 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 29 ms 13268 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 5980 KB Output is correct
2 Correct 13 ms 6012 KB Output is correct
3 Correct 17 ms 6416 KB Output is correct
4 Correct 20 ms 6476 KB Output is correct
5 Correct 14 ms 6488 KB Output is correct
6 Correct 16 ms 7076 KB Output is correct
7 Correct 18 ms 6764 KB Output is correct
8 Correct 19 ms 6368 KB Output is correct
9 Correct 16 ms 6368 KB Output is correct
10 Correct 16 ms 6748 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 4 ms 4136 KB Output is correct
13 Correct 4 ms 4164 KB Output is correct
14 Correct 4 ms 4056 KB Output is correct
15 Correct 4 ms 4056 KB Output is correct
16 Correct 4 ms 4152 KB Output is correct
17 Correct 4 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 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 4 ms 4056 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 29 ms 13268 KB Output isn't correct
2 Halted 0 ms 0 KB -