Submission #622829

# Submission time Handle Problem Language Result Execution time Memory
622829 2022-08-04T16:13:44 Z PoonYaPat City Mapping (NOI18_citymapping) C++14
57 / 100
31 ms 8448 KB
#include "citymapping.h"

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

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

ll get(int  x, int y) {
    if (!dis[x][y]) dis[x][y]=dis[y][x]=get_distance(x,y);
    return dis[x][y];
}

void find(int x) {
    int r,l;
    ll longest=0;
    vector<pii> temp; //dis and node in backbone
    vector<int> tree;

    v[x].push_back(x);
    for (auto s : v[x]) if (get(x,s)>longest) longest=get(x,s), r=s;
    longest=0;
    for (auto s : v[x]) if (get(r,s)>longest) longest=get(r,s), l=s;
    for (auto s : v[x]) {
        if (r==s) continue;
        if (get(r,s)+get(s,l)==get(r,l)) temp.push_back(pii(get(r,s),s));
        else tree.push_back(s);
    }

    sort(temp.begin(),temp.end());
    ans.push_back(t(r,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));
    }
    v[x].clear();
    for (auto s : tree) {
        for (auto b : temp) {
            if (dis[r][s]-(dis[r][s]+dis[s][l]-dis[r][l])/2==b.first) {
                v[b.second].push_back(s);
                dis[b.second][s]=dis[s][b.second]=(dis[r][s]+dis[s][l]-dis[r][l])/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;
    for (int i=2; i<=n; ++i) v[1].push_back(i);
    find(1);

    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:38:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |     for (int i=1; i<temp.size(); ++i) {
      |                   ~^~~~~~~~~~~~
citymapping.cpp: In function 'void find_roads(int, int, int*, int*, int*)':
citymapping.cpp:60: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]
   60 |     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:44:56: warning: 'r' may be used uninitialized in this function [-Wmaybe-uninitialized]
   44 |             if (dis[r][s]-(dis[r][s]+dis[s][l]-dis[r][l])/2==b.first) {
      |                                                ~~~~~~~~^
citymapping.cpp:44:56: warning: 'l' may be used uninitialized in this function [-Wmaybe-uninitialized]
# Verdict Execution time Memory Grader output
1 Correct 6 ms 8276 KB Correct: 2994 out of 500000 queries used.
2 Correct 5 ms 8020 KB Correct: 4494 out of 500000 queries used.
3 Correct 5 ms 8304 KB Correct: 7320 out of 500000 queries used.
4 Correct 6 ms 8276 KB Correct: 8478 out of 500000 queries used.
5 Correct 5 ms 8148 KB Correct: 12087 out of 500000 queries used.
# Verdict Execution time Memory Grader output
1 Correct 6 ms 8276 KB Correct: 2994 out of 500000 queries used.
2 Correct 5 ms 8020 KB Correct: 4494 out of 500000 queries used.
3 Correct 5 ms 8304 KB Correct: 7320 out of 500000 queries used.
4 Correct 6 ms 8276 KB Correct: 8478 out of 500000 queries used.
5 Correct 5 ms 8148 KB Correct: 12087 out of 500000 queries used.
6 Correct 5 ms 6776 KB Correct: 2985 out of 500000 queries used.
7 Correct 7 ms 8404 KB Correct: 21880 out of 500000 queries used.
8 Correct 5 ms 8276 KB Correct: 7282 out of 500000 queries used.
9 Correct 5 ms 8276 KB Correct: 8735 out of 500000 queries used.
10 Correct 5 ms 8020 KB Correct: 7230 out of 500000 queries used.
# Verdict Execution time Memory Grader output
1 Correct 4 ms 6228 KB Correct: 2970 out of 12000 queries used.
2 Correct 6 ms 6484 KB Correct: 2976 out of 12000 queries used.
3 Correct 4 ms 6868 KB Correct: 2997 out of 12000 queries used.
4 Correct 5 ms 7124 KB Correct: 2976 out of 12000 queries used.
5 Correct 6 ms 8276 KB Correct: 2970 out of 12000 queries used.
# Verdict Execution time Memory Grader output
1 Correct 4 ms 6228 KB Correct: 2970 out of 12000 queries used.
2 Correct 6 ms 6484 KB Correct: 2976 out of 12000 queries used.
3 Correct 4 ms 6868 KB Correct: 2997 out of 12000 queries used.
4 Correct 5 ms 7124 KB Correct: 2976 out of 12000 queries used.
5 Correct 6 ms 8276 KB Correct: 2970 out of 12000 queries used.
6 Correct 5 ms 8276 KB Correct: 2991 out of 12000 queries used.
7 Correct 5 ms 6868 KB Correct: 2985 out of 12000 queries used.
8 Correct 5 ms 7636 KB Correct: 2997 out of 12000 queries used.
9 Correct 4 ms 7252 KB Correct: 2988 out of 12000 queries used.
10 Correct 5 ms 7460 KB Correct: 2979 out of 12000 queries used.
# Verdict Execution time Memory Grader output
1 Correct 6 ms 8276 KB Correct: 2994 out of 500000 queries used.
2 Correct 5 ms 8020 KB Correct: 4494 out of 500000 queries used.
3 Correct 5 ms 8304 KB Correct: 7320 out of 500000 queries used.
4 Correct 6 ms 8276 KB Correct: 8478 out of 500000 queries used.
5 Correct 5 ms 8148 KB Correct: 12087 out of 500000 queries used.
6 Correct 5 ms 6776 KB Correct: 2985 out of 500000 queries used.
7 Correct 7 ms 8404 KB Correct: 21880 out of 500000 queries used.
8 Correct 5 ms 8276 KB Correct: 7282 out of 500000 queries used.
9 Correct 5 ms 8276 KB Correct: 8735 out of 500000 queries used.
10 Correct 5 ms 8020 KB Correct: 7230 out of 500000 queries used.
11 Correct 4 ms 6228 KB Correct: 2970 out of 12000 queries used.
12 Correct 6 ms 6484 KB Correct: 2976 out of 12000 queries used.
13 Correct 4 ms 6868 KB Correct: 2997 out of 12000 queries used.
14 Correct 5 ms 7124 KB Correct: 2976 out of 12000 queries used.
15 Correct 6 ms 8276 KB Correct: 2970 out of 12000 queries used.
16 Correct 5 ms 8276 KB Correct: 2991 out of 12000 queries used.
17 Correct 5 ms 6868 KB Correct: 2985 out of 12000 queries used.
18 Correct 5 ms 7636 KB Correct: 2997 out of 12000 queries used.
19 Correct 4 ms 7252 KB Correct: 2988 out of 12000 queries used.
20 Correct 5 ms 7460 KB Correct: 2979 out of 12000 queries used.
21 Correct 5 ms 8276 KB Correct: 2985 out of 25000 queries used.
22 Correct 6 ms 8020 KB Correct: 7719 out of 25000 queries used.
23 Correct 6 ms 8148 KB Correct: 4529 out of 25000 queries used.
24 Correct 7 ms 8276 KB Correct: 5901 out of 25000 queries used.
25 Correct 6 ms 8248 KB Correct: 7321 out of 25000 queries used.
26 Correct 5 ms 8276 KB Correct: 7155 out of 25000 queries used.
27 Correct 5 ms 8276 KB Correct: 7174 out of 25000 queries used.
28 Correct 5 ms 8276 KB Correct: 7536 out of 25000 queries used.
29 Correct 6 ms 8276 KB Correct: 7765 out of 25000 queries used.
30 Correct 6 ms 8232 KB Correct: 7987 out of 25000 queries used.
31 Correct 5 ms 8276 KB Correct: 8445 out of 25000 queries used.
32 Correct 4 ms 6356 KB Correct: 2982 out of 25000 queries used.
33 Correct 6 ms 8312 KB Correct: 8275 out of 25000 queries used.
34 Correct 8 ms 8308 KB Correct: 8410 out of 25000 queries used.
35 Correct 5 ms 8276 KB Correct: 8373 out of 25000 queries used.
36 Correct 7 ms 8308 KB Correct: 8472 out of 25000 queries used.
37 Correct 24 ms 8312 KB Correct: 8375 out of 25000 queries used.
38 Correct 5 ms 8276 KB Correct: 8507 out of 25000 queries used.
39 Correct 5 ms 8276 KB Correct: 8415 out of 25000 queries used.
40 Correct 6 ms 8276 KB Correct: 8486 out of 25000 queries used.
41 Correct 5 ms 8276 KB Correct: 8434 out of 25000 queries used.
42 Correct 6 ms 8276 KB Correct: 8449 out of 25000 queries used.
43 Correct 5 ms 8276 KB Correct: 2991 out of 25000 queries used.
44 Correct 8 ms 8276 KB Correct: 8343 out of 25000 queries used.
45 Correct 6 ms 8316 KB Correct: 8349 out of 25000 queries used.
46 Correct 7 ms 8276 KB Correct: 8362 out of 25000 queries used.
47 Correct 6 ms 8308 KB Correct: 8451 out of 25000 queries used.
48 Correct 5 ms 8312 KB Correct: 8495 out of 25000 queries used.
49 Correct 5 ms 8320 KB Correct: 8458 out of 25000 queries used.
50 Correct 6 ms 8276 KB Correct: 8451 out of 25000 queries used.
51 Correct 6 ms 8276 KB Correct: 8449 out of 25000 queries used.
52 Correct 7 ms 8356 KB Correct: 8427 out of 25000 queries used.
53 Correct 5 ms 8276 KB Correct: 8758 out of 25000 queries used.
54 Correct 8 ms 8448 KB Correct: 23570 out of 25000 queries used.
55 Correct 6 ms 8276 KB Correct: 8418 out of 25000 queries used.
56 Correct 6 ms 8276 KB Correct: 8487 out of 25000 queries used.
57 Correct 5 ms 8308 KB Correct: 8789 out of 25000 queries used.
58 Correct 5 ms 8276 KB Correct: 8349 out of 25000 queries used.
59 Correct 6 ms 8276 KB Correct: 8352 out of 25000 queries used.
60 Correct 6 ms 8276 KB Correct: 8553 out of 25000 queries used.
61 Correct 5 ms 7796 KB Correct: 7946 out of 25000 queries used.
62 Correct 5 ms 7892 KB Correct: 7337 out of 25000 queries used.
63 Correct 6 ms 8088 KB Correct: 8023 out of 25000 queries used.
64 Correct 5 ms 7968 KB Correct: 7595 out of 25000 queries used.
65 Correct 5 ms 8148 KB Correct: 11746 out of 25000 queries used.
66 Correct 6 ms 8276 KB Correct: 7474 out of 25000 queries used.
67 Correct 5 ms 8276 KB Correct: 4830 out of 25000 queries used.
68 Incorrect 31 ms 8304 KB Too many calls to get_distance().
69 Halted 0 ms 0 KB -