답안 #1003888

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1003888 2024-06-20T19:37:11 Z asdasdqwer 꿈 (IOI13_dreaming) C++14
0 / 100
42 ms 14548 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];
  return vals[0] + vals[1] + 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 42 ms 14548 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 42 ms 14548 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 6460 KB Output is correct
2 Incorrect 14 ms 6544 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 42 ms 14548 KB Output isn't correct
2 Halted 0 ms 0 KB -