답안 #741668

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
741668 2023-05-14T14:14:48 Z vjudge1 꿈 (IOI13_dreaming) C++17
컴파일 오류
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];
ll sz[100005];
vector<int> group;

int getSize(int n, int p = -1) {
    visited[n] = 1;
    group.push_back(n);
    sz[n] = 0;
    for (auto x : g[n]) {
        if (x.first == p) continue;
        sz[n] += getSize(x.first, n) + x.second;
    }
    return sz[n];
}

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]});
    }
    bool visited[N + 2];
    vector<int> groups;
    for (int i = 0; i < N; i++) {
        if (visited[i]) continue;
        group.clear();
        getSize(i);
        int diff = INT_MAX;
        for (auto x : group) {
            if (abs(sz[i] / 2 - sz[x]) < diff) {
                diff = abs(sz[i] / 2 - sz[x]);
            }
        }
        group.push_back(diff);
    }
    sort(all(group));
    reverse(all(group));
    int ans = 0;
    for (int i = 1; i < group.size(); i++) {
        ans = max(ans, group[i] + group[0] + L);
    }
    return ans;
}

Compilation message

dreaming.cpp: In function 'int getSize(int, int)':
dreaming.cpp:15:5: error: 'visited' was not declared in this scope
   15 |     visited[n] = 1;
      |     ^~~~~~~
dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:47:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |     for (int i = 1; i < group.size(); i++) {
      |                     ~~^~~~~~~~~~~~~~