답안 #622434

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
622434 2022-08-04T09:28:02 Z PoonYaPat City Mapping (NOI18_citymapping) C++14
컴파일 오류
0 ms 0 KB
#include "citymapping.h"
#include "grader.cpp"

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef tuple<int,int,int> t;

int n;
vector<int> v[1001];
vector<t> ans;
ll dis[1001][1001];

void find(int x) { //have v[x] represent the node which has x as it child, know dis[x][s]
    int r;
    ll longest=0;
    vector<pii> temp; //dis and node in backbone
    vector<int> tree;

    for (auto s : v[x]) if (dis[x][s]>longest) longest=dis[x][s], r=s; //find backbone

    for (auto s : v[x]) {
        dis[s][r]=dis[r][s]=get_distance(s,r);

        if (dis[x][s]+dis[s][r]==dis[x][r]) temp.push_back(pii(dis[x][s],s)); //in backbone
        else tree.push_back(s);
    }

    sort(temp.begin(),temp.end());
    ans.push_back(t(x,temp[0].second,temp[0].first));

    for (int i=1; i<temp.size(); ++i) {
        ans.push_back(t(temp[i-1].second,temp[i].second,temp[i].first-temp[i-1].first));
    }

    for (auto s : tree) {
        int t=dis[x][s]-(dis[x][s]+dis[s][r]-dis[x][r])/2;
        for (auto b : temp) {
            if (t==b.first) {
                v[b.second].push_back(s);
                dis[b.second][s]=dis[s][b.second]=(dis[x][s]+dis[s][r]-dis[x][r])/2;
                break;
            }
        }
    }

    for (auto s : temp) if (v[s.second].size()) find(s.second);
}

void find_roads(int N, int Q, int A[], int B[], int W[]) {
    n=N;

    //find rim
    int l=1,r=2;
    for (int x=3; x<=n; ++x) {
        dis[x][l]=dis[l][x]=get_distance(x,l);
        dis[x][r]=dis[r][x]=get_distance(r,x);
        if (!dis[l][r]) dis[l][r]=dis[r][l]=get_distance(l,r);

        if (dis[x][l]+dis[l][r]==dis[x][r]) l=x;
    }

    for (int i=1; i<=n; ++i) {
        if (i==l) continue;
        v[l].push_back(i);
        if (!dis[l][i]) dis[l][i]=dis[i][l]=get_distance(i,l);
    }
    find(l);

    for (int i=0; i<ans.size(); ++i) tie(A[i],B[i],W[i])=ans[i];
	return;
}

Compilation message

citymapping.cpp: In function 'void find(int)':
citymapping.cpp:33:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |     for (int i=1; i<temp.size(); ++i) {
      |                   ~^~~~~~~~~~~~
citymapping.cpp: In function 'void find_roads(int, int, int*, int*, int*)':
citymapping.cpp:71:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::tuple<int, int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |     for (int i=0; i<ans.size(); ++i) tie(A[i],B[i],W[i])=ans[i];
      |                   ~^~~~~~~~~~~
citymapping.cpp: In function 'void find(int)':
citymapping.cpp:38:54: warning: 'r' may be used uninitialized in this function [-Wmaybe-uninitialized]
   38 |         int t=dis[x][s]-(dis[x][s]+dis[s][r]-dis[x][r])/2;
      |                                              ~~~~~~~~^
/usr/bin/ld: /tmp/ccS7PUeX.o: in function `get_distance(int, int)':
grader.cpp:(.text+0x470): multiple definition of `get_distance(int, int)'; /tmp/ccPCx3NY.o:citymapping.cpp:(.text+0xab0): first defined here
/usr/bin/ld: /tmp/ccS7PUeX.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccPCx3NY.o:citymapping.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status