Submission #288287

# Submission time Handle Problem Language Result Execution time Memory
288287 2020-09-01T11:39:02 Z BeanZ Dreaming (IOI13_dreaming) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
//#include "dreaming.h"

using namespace std;

#define ll long long
#define endl '\n'
const int N = 1e5 + 5;
ll dp[N], res, vis[N], lg, cur;
vector<pair<ll, ll>> node[N];
void dfsFirst(ll u){
        vis[u] = 1;
        for (auto j : node[u]){
                if (vis[j.first]) continue;
                dfsFirst(j.first);
                dp[u] = max(dp[u], dp[j.first] + j.second);
        }
}
void reroot(ll u, ll v){
        dp[u] = 0;
        for (auto j : node[u]){
                if (j.first == v) continue;
                dp[u] = max(dp[u], dp[j.first] + j.second);
        }
        dp[v] = 0;
        for (auto j : node[v]){
                dp[v] = max(dp[v], dp[j.first] + j.second);
        }
        res = min(res, dp[v]);
}
void dfs(ll u, ll p){
        for (auto j : node[u]){
                if (j.first == p) continue;
                reroot(u, j.first);
                dfs(j.first, u);
                reroot(j.first, u);
        }
}
void FindFirstNode(ll u, ll p, ll dist){
        if (dist > lg){
                lg = dist;
                cur = u;
        }
        for (auto j : node[u]){
                if (j.first == p) continue;
                FindFirstNode(j.first, u, dist + j.second);
        }
}
void FindDia(ll u, ll p, ll dist){
        if (dist > lg){
                lg = dist;
        }
        for (auto j : node[u]){
                if (j.first == p) continue;
                FindDia(j.first, u, dist + j.second);
        }
}
int travelTime(int N, int M, int L, int A[],int B[],int T[]){
        for (int i = 1; i <= M; i++){
                node[A[i - 1] + 1].push_back({B[i - 1] + 1, T[i - 1]});
                node[B[i - 1] + 1].push_back({A[i - 1] + 1, T[i - 1]});
        }
        priority_queue<ll> pq;
        ll ans = 0;
        for (int i = 1; i <= N; i++){
                if (!vis[i]){
                        dfsFirst(i);
                        res = dp[i];
                        dfs(i, i);
                        lg = -1;
                        FindFirstNode(i, i, 0);
                        lg = -1;
                        FindDia(cur, cur, 0);
                        ans = max(ans, lg);
                        pq.push(res);
                }
        }
        ll root = pq.top();
        pq.pop();
        ll mx = -1e18;
        while (pq.size()){
                ans = max(ans, pq.top() + 2 * L + mx);
                ans = max(ans, pq.top() + L + root);
                mx = max(mx, pq.top());
                pq.pop();
        }
        return ans;
}
int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        if (fopen("VietCT.INP", "r")){
                freopen("VietCT.INP", "r", stdin);
                freopen("VietCT.OUT", "w", stdout);
        }
        int n, m, l;
        cin >> n >> m >> l;
        vector<int> a, b, t;
        for (int i = 1; i <= m; i++){
                int u, v, c;
                cin >> u >> v >> c;
                a.push_back(u + 1);
                b.push_back(v + 1);
                t.push_back(c);
        }
        cout << travelTime(n, m, l, a, b, t);
}
/*
6 2 1000
0 1 10
2 3 10
*/

Compilation message

dreaming.cpp: In function 'int main()':
dreaming.cpp:106:37: error: cannot convert 'std::vector<int>' to 'int*'
  106 |         cout << travelTime(n, m, l, a, b, t);
      |                                     ^
      |                                     |
      |                                     std::vector<int>
dreaming.cpp:58:41: note:   initializing argument 4 of 'int travelTime(int, int, int, int*, int*, int*)'
   58 | int travelTime(int N, int M, int L, int A[],int B[],int T[]){
      |                                     ~~~~^~~
dreaming.cpp:93:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   93 |                 freopen("VietCT.INP", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
dreaming.cpp:94:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   94 |                 freopen("VietCT.OUT", "w", stdout);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~