답안 #843702

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
843702 2023-09-04T12:52:39 Z nonono 꿈 (IOI13_dreaming) C++17
컴파일 오류
0 ms 0 KB
#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std;

const int mxN = 100005;

vector<vector<pair<int, int>>> adj(mxN);
int mark[mxN];
int high[mxN], _high[mxN];
vector<int> vertex;

void dfs(int u, int par) {
    vertex.push_back(u);
    mark[u] = 1;
    high[u] = 0;
    
    for(auto [v, w] : adj[u]) {
        if(v == par) continue ;
        dfs(v, u);
        high[u] = max(high[u], high[v] + w);
    }
}

void reroot(int u, int par) {
    vector<pair<int, int>> k;
    vector<int> L, R;
    
    for(auto [v, w] : adj[u]) {
        if(v == par) continue ;
        k.push_back({v, w});
    }
   
   for(int i = 0; i < k.size(); i ++) {
       auto [v, w] = k[i];
       L.push_back(max((!L.empty() ? L.back() : 0), high[v] + w));
   }
   
   for(int i = 0; i < k.size(); i ++) {
       auto [v, w] = k[k.size() - 1 - i];
       R.push_back(max((!R.empty() ? R.back() : 0), high[v] + w));
   }
   
   reverse(R.begin(), R.end());
   
   for(int i = 0; i < k.size(); i ++) {
       auto [v, w] = k[i];
       if(v == par) continue ;
       
       _high[v] = max(_high[v], _high[u] + w);
       if(i) _high[v] = max(_high[v], L[i - 1] + w);
       if(i + 1 < R.size()) _high[v] = max(_high[v], R[i + 1] + w);
       reroot(v, u);
   }
}

int travelTime(int N, int M, int L, vector<int> A, vector<int> B, vector<int> T) {
    
    for(int i = 0; i < M; i ++) {
        adj[A[i]].push_back({B[i], T[i]});
        adj[B[i]].push_back({A[i], T[i]});
    }
    
    vector<int> f;
    int ans = 0;
    
    for(int i = 0; i < N; i ++) {
        if(!mark[i]) {
            dfs(i, i);
            reroot(i, i);
            
            int timer = max(high[vertex.back()], _high[vertex.back()]);
            for(int x : vertex) {
                ans = max(ans, high[x] + _high[x]);
                timer = min(timer, max(high[x], _high[x]));
            }
            
            f.push_back(timer);
            vertex.clear();
        }
    }
    
    sort(f.begin(), f.end());
    
    if(f.size() > 1) {
        ans = max(ans, f[f.back()] + f[f.size() - 2] + L);
    }
    
    return ans;
}

Compilation message

dreaming.cpp: In function 'void reroot(int, int)':
dreaming.cpp:33:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |    for(int i = 0; i < k.size(); i ++) {
      |                   ~~^~~~~~~~~~
dreaming.cpp:38:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |    for(int i = 0; i < k.size(); i ++) {
      |                   ~~^~~~~~~~~~
dreaming.cpp:45:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |    for(int i = 0; i < k.size(); i ++) {
      |                   ~~^~~~~~~~~~
dreaming.cpp:51:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |        if(i + 1 < R.size()) _high[v] = max(_high[v], R[i + 1] + w);
      |           ~~~~~~^~~~~~~~~~
/usr/bin/ld: /tmp/cc2zem9Y.o: in function `main':
grader.c:(.text.startup+0xd1): undefined reference to `travelTime'
collect2: error: ld returned 1 exit status