답안 #963479

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
963479 2024-04-15T06:53:20 Z sleepntsheep City Mapping (NOI18_citymapping) C++17
0 / 100
1 ms 604 KB
#include "citymapping.h"
#include <vector>
#include <algorithm>

#define N 1005

void find_roads(int n, int q, int A[], int B[], int W[]) {
    if (q != 12000)
        return;

    int root = 1, ad = -1;
    int d[N] = { 0 }, e[N] = { 0 };
    for (int i = 2; i <= n; ++i)
    {
        d[i] = get_distance(root, i);
        if (ad == -1 || d[i] < d[ad])
            ad = i;
    }

    for (int i = 1; i <= n; ++i)
        e[i] = get_distance(ad, i);

    std::vector<int> left, right;

    left.push_back(ad);
    for (int i = 1; i <= n; ++i)
    {
        if (i == ad || i == root)
            continue;
        if (d[i] > d[ad]) left.push_back(i);
        else right.push_back(i);
    }

    std::sort(left.begin(), left.end(), [&](int i, int j){ return d[i] < d[j] ; });
    std::sort(right.begin(), right.end(), [&](int i, int j){ return d[i] < d[j] ; });

    for (int pre = root, i = 0; i < left.size(); ++i)
    {
        A[i] = pre;
        B[i] = left[i];
        W[i] = d[left[i]] - d[pre];
        pre = B[i];
    }

    for (int pre = root, j = 0, i = left.size(); i < N - 1; ++i, ++j)
    {
        A[i] = pre;
        B[i] = right[i];
        W[i] = d[right[i]] - d[pre];
        pre = B[i];
    }
	return;
}

Compilation message

citymapping.cpp: In function 'void find_roads(int, int, int*, int*, int*)':
citymapping.cpp:37:35: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |     for (int pre = root, i = 0; i < left.size(); ++i)
      |                                 ~~^~~~~~~~~~~~~
citymapping.cpp:12:23: warning: variable 'e' set but not used [-Wunused-but-set-variable]
   12 |     int d[N] = { 0 }, e[N] = { 0 };
      |                       ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 604 KB Reported list of edges differ from actual.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 604 KB Reported list of edges differ from actual.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 604 KB Reported list of edges differ from actual.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 604 KB Reported list of edges differ from actual.
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 604 KB Reported list of edges differ from actual.
2 Halted 0 ms 0 KB -