Submission #742179

# Submission time Handle Problem Language Result Execution time Memory
742179 2023-05-15T17:55:42 Z vjudge1 Dreaming (IOI13_dreaming) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#include "dreaming.h"

using namespace std;

#define endl '\n'
#define ll long long
#define all(x) x.begin(), x.end()

vector<pair<int, int>> g[100005];
vector<int> group;
int mx = 0, ans = 0;
bool visited[100005];

void dfs(int n, int p, int d, vector<pair<int, int>> &path) {
    visited[n] = 1;
    path.push_back({n, d});
    for (auto x : g[n]) {
        if (p != x.first) {
            dfs(x.first, n, d + x.second, path);
        }
    }
}

void solve(int n) {
    vector<pair<int, int>> d, d2;
    dfs(n, -1, 0, d);
    int node, maxDist = -1;
    for (auto x : d) {
        if (x.second > maxDist) {
            maxDist = x.second;
            node = x.first;
        }
    }
    d.clear();
    dfs(node, -1, 0, d);
    map<int, int> mp;
    maxDist = -1;
    for (auto x : d) {
        mp[x.first] = x.second;
        if (x.second > maxDist) {
            maxDist = x.second;
            node = x.first;
        }
    }
    mx = max(mx, x.second);
    dfs(node, -1, 0, d2);
    for (auto x : d2) {
        ans = min(ans, max(x.second, mp[x.first]));
    }
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
    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> groups;
    for (int i = 0; i < N; i++) {
        if (visited[i]) continue;
        ans = INT_MAX;
        solve(i);
        groups.push_back(ans);
    }
    sort(all(groups));
    reverse(all(groups));
    if (groups.size() == 1) return max(groups[0], mx);
    if (groups.size() == 2) return max(groups[0] + groups[1] + L, mx);
    return max({groups[0] + groups[1] + L, groups[1] + groups[2] + 2 * L, mx});
}

Compilation message

dreaming.cpp: In function 'void solve(int)':
dreaming.cpp:46:18: error: 'x' was not declared in this scope
   46 |     mx = max(mx, x.second);
      |                  ^