답안 #332764

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
332764 2020-12-03T08:47:57 Z CursedCode 꿈 (IOI13_dreaming) C++14
0 / 100
55 ms 14700 KB
#include "dreaming.h"
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
 
using namespace std;
vector<pair<int, int> > adj[100005];
int go[100005]; 
int cost[1000005] = {0}; 
int vis[1000005] = {0};
int n;
int id = 0, max_path = 0;
// grap bolgonii median max
vector<int> median;
void dfs(int u, int x, int path){
  if(max_path <= path) {
    id = u;
    max_path = path;
  }
  vis[u] = 1;
  for(int i = 0; i < adj[u].size(); i++){
    int v, e;
    v = adj[u][i].first;
    e = adj[u][i].second;
    if(v != x) {
        dfs(v, u, path + e);
    }
  }
}
void dfss(int u, int x){
  if(max_path <= cost[u]) {
    id = u;
    max_path = cost[u];
  }
  vis[u] = 1;
  go[u] = x;
  for(int i = 0; i < adj[u].size(); i++){
    int v, e;
    v = adj[u][i].first;
    e = adj[u][i].second;
    if(v != x) {
        cost[v] = cost[u] + e;
        dfss(v, u);
    }
  }
}
int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
  n = N;
  memset(go, -1, sizeof(go));
  for(int i = 0; i < M; i++){
      adj[A[i]].pb(mp(B[i], T[i]));
      adj[B[i]].pb(mp(A[i], T[i]));
  }
  for(int i = 0; i < n; i++)
    if(vis[i] == 0){
 
      id = 0;
      max_path = 0;
      dfs(i, -1, 0);
      max_path = 0;
      dfss(id, -1);
 
      int diameter = max_path;
      int u = id;
      int path = 1e9;
      while(u != -1){   
          path = min(path, max(diameter - cost[u], cost[u]));
          u = go[u];
      }
      
      median.pb(path);
    }
    sort(median.begin(), median.end());
    int sz = median.size();
    int res = 0;
    res = max(res, median[sz - 1] + median[sz - 2] + L);
    if(sz > 2) res = max(res, median[sz - 2] + median[sz - 3] + 2 * L);
    return res;
}
 
 
 
#define MAX_N 100000
 
int A[MAX_N];
int B[MAX_N];
int T[MAX_N];

Compilation message

dreaming.cpp: In function 'void dfs(int, int, int)':
dreaming.cpp:21:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |   for(int i = 0; i < adj[u].size(); i++){
      |                  ~~^~~~~~~~~~~~~~~
dreaming.cpp: In function 'void dfss(int, int)':
dreaming.cpp:37:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |   for(int i = 0; i < adj[u].size(); i++){
      |                  ~~^~~~~~~~~~~~~~~
dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:54:3: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   54 |   for(int i = 0; i < n; i++)
      |   ^~~
dreaming.cpp:73:5: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   73 |     sort(median.begin(), median.end());
      |     ^~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 55 ms 14700 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 55 ms 14700 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 55 ms 14700 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 7024 KB Output is correct
2 Correct 29 ms 7020 KB Output is correct
3 Correct 32 ms 6896 KB Output is correct
4 Correct 29 ms 7032 KB Output is correct
5 Correct 27 ms 7020 KB Output is correct
6 Correct 28 ms 7408 KB Output is correct
7 Correct 28 ms 7152 KB Output is correct
8 Correct 25 ms 6896 KB Output is correct
9 Correct 28 ms 6888 KB Output is correct
10 Correct 27 ms 7016 KB Output is correct
11 Correct 2 ms 3052 KB Output is correct
12 Correct 7 ms 4328 KB Output is correct
13 Correct 7 ms 4456 KB Output is correct
14 Correct 7 ms 4328 KB Output is correct
15 Correct 7 ms 4456 KB Output is correct
16 Correct 7 ms 4328 KB Output is correct
17 Correct 6 ms 4200 KB Output is correct
18 Correct 7 ms 4456 KB Output is correct
19 Correct 7 ms 4328 KB Output is correct
20 Incorrect 2 ms 3052 KB Output isn't correct
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 55 ms 14700 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 55 ms 14700 KB Output isn't correct
2 Halted 0 ms 0 KB -