답안 #741669

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
741669 2023-05-14T14:15:36 Z vjudge1 꿈 (IOI13_dreaming) C++17
0 / 100
35 ms 11148 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;
bool visited[100005];

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]});
    }
    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 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++) {
      |                     ~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 35 ms 11148 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 35 ms 11148 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 17 ms 5812 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 35 ms 11148 KB Output isn't correct
2 Halted 0 ms 0 KB -