Submission #622814

# Submission time Handle Problem Language Result Execution time Memory
622814 2022-08-04T15:20:02 Z PoonYaPat City Mapping (NOI18_citymapping) C++14
63.53 / 100
8 ms 8436 KB
#include "citymapping.h"
//#include "grader.cpp"

#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;
    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]) {
        if (get(x,s)+get(s,r)==get(x,r)) temp.push_back(pii(get(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) {
        for (auto b : temp) {
            if (dis[x][s]-(dis[x][s]+dis[s][r]-dis[x][r])/2==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;
    ll longest=0;
    for (int i=1; i<n; ++i) {
        if (get(n,i)>longest) {
            longest=dis[n][i];
            l=i;
        }
    }

    for (int i=1; i<=n; ++i) {
        if (i==l) continue;
        v[l].push_back(i);
        get(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:36: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]
   36 |     for (int i=1; i<temp.size(); ++i) {
      |                   ~^~~~~~~~~~~~
citymapping.cpp: In function 'void find_roads(int, int, int*, int*, int*)':
citymapping.cpp:73: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]
   73 |     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:42:56: warning: 'r' may be used uninitialized in this function [-Wmaybe-uninitialized]
   42 |             if (dis[x][s]-(dis[x][s]+dis[s][r]-dis[x][r])/2==b.first) {
      |                                                ~~~~~~~~^
# Verdict Execution time Memory Grader output
1 Correct 6 ms 8276 KB Correct: 2992 out of 500000 queries used.
2 Correct 5 ms 7872 KB Correct: 3494 out of 500000 queries used.
3 Correct 7 ms 8164 KB Correct: 5525 out of 500000 queries used.
4 Correct 5 ms 8276 KB Correct: 6427 out of 500000 queries used.
5 Correct 6 ms 8148 KB Correct: 11605 out of 500000 queries used.
# Verdict Execution time Memory Grader output
1 Correct 6 ms 8276 KB Correct: 2992 out of 500000 queries used.
2 Correct 5 ms 7872 KB Correct: 3494 out of 500000 queries used.
3 Correct 7 ms 8164 KB Correct: 5525 out of 500000 queries used.
4 Correct 5 ms 8276 KB Correct: 6427 out of 500000 queries used.
5 Correct 6 ms 8148 KB Correct: 11605 out of 500000 queries used.
6 Correct 4 ms 6740 KB Correct: 2983 out of 500000 queries used.
7 Correct 6 ms 8436 KB Correct: 16041 out of 500000 queries used.
8 Correct 5 ms 8276 KB Correct: 5590 out of 500000 queries used.
9 Correct 5 ms 8276 KB Correct: 6667 out of 500000 queries used.
10 Correct 5 ms 8020 KB Correct: 5636 out of 500000 queries used.
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6100 KB Correct: 2968 out of 12000 queries used.
2 Correct 5 ms 6484 KB Correct: 2974 out of 12000 queries used.
3 Correct 4 ms 6868 KB Correct: 2995 out of 12000 queries used.
4 Correct 5 ms 7124 KB Correct: 2974 out of 12000 queries used.
5 Correct 4 ms 8304 KB Correct: 2968 out of 12000 queries used.
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6100 KB Correct: 2968 out of 12000 queries used.
2 Correct 5 ms 6484 KB Correct: 2974 out of 12000 queries used.
3 Correct 4 ms 6868 KB Correct: 2995 out of 12000 queries used.
4 Correct 5 ms 7124 KB Correct: 2974 out of 12000 queries used.
5 Correct 4 ms 8304 KB Correct: 2968 out of 12000 queries used.
6 Correct 5 ms 8276 KB Correct: 2989 out of 12000 queries used.
7 Correct 4 ms 6868 KB Correct: 2983 out of 12000 queries used.
8 Correct 7 ms 7508 KB Correct: 2995 out of 12000 queries used.
9 Correct 4 ms 7252 KB Correct: 2986 out of 12000 queries used.
10 Correct 5 ms 7508 KB Correct: 2977 out of 12000 queries used.
# Verdict Execution time Memory Grader output
1 Correct 6 ms 8276 KB Correct: 2992 out of 500000 queries used.
2 Correct 5 ms 7872 KB Correct: 3494 out of 500000 queries used.
3 Correct 7 ms 8164 KB Correct: 5525 out of 500000 queries used.
4 Correct 5 ms 8276 KB Correct: 6427 out of 500000 queries used.
5 Correct 6 ms 8148 KB Correct: 11605 out of 500000 queries used.
6 Correct 4 ms 6740 KB Correct: 2983 out of 500000 queries used.
7 Correct 6 ms 8436 KB Correct: 16041 out of 500000 queries used.
8 Correct 5 ms 8276 KB Correct: 5590 out of 500000 queries used.
9 Correct 5 ms 8276 KB Correct: 6667 out of 500000 queries used.
10 Correct 5 ms 8020 KB Correct: 5636 out of 500000 queries used.
11 Correct 3 ms 6100 KB Correct: 2968 out of 12000 queries used.
12 Correct 5 ms 6484 KB Correct: 2974 out of 12000 queries used.
13 Correct 4 ms 6868 KB Correct: 2995 out of 12000 queries used.
14 Correct 5 ms 7124 KB Correct: 2974 out of 12000 queries used.
15 Correct 4 ms 8304 KB Correct: 2968 out of 12000 queries used.
16 Correct 5 ms 8276 KB Correct: 2989 out of 12000 queries used.
17 Correct 4 ms 6868 KB Correct: 2983 out of 12000 queries used.
18 Correct 7 ms 7508 KB Correct: 2995 out of 12000 queries used.
19 Correct 4 ms 7252 KB Correct: 2986 out of 12000 queries used.
20 Correct 5 ms 7508 KB Correct: 2977 out of 12000 queries used.
21 Correct 5 ms 8276 KB Correct: 2983 out of 25000 queries used.
22 Correct 5 ms 7764 KB Correct: 5871 out of 25000 queries used.
23 Correct 5 ms 8020 KB Correct: 3516 out of 25000 queries used.
24 Correct 6 ms 8168 KB Correct: 4822 out of 25000 queries used.
25 Correct 5 ms 8276 KB Correct: 4645 out of 25000 queries used.
26 Correct 5 ms 8148 KB Correct: 5388 out of 25000 queries used.
27 Correct 5 ms 8276 KB Correct: 5524 out of 25000 queries used.
28 Correct 5 ms 8284 KB Correct: 5659 out of 25000 queries used.
29 Correct 8 ms 8276 KB Correct: 5916 out of 25000 queries used.
30 Correct 5 ms 8276 KB Correct: 6128 out of 25000 queries used.
31 Correct 6 ms 8276 KB Correct: 6454 out of 25000 queries used.
32 Correct 4 ms 6484 KB Correct: 2980 out of 25000 queries used.
33 Correct 5 ms 8276 KB Correct: 6423 out of 25000 queries used.
34 Correct 5 ms 8236 KB Correct: 6452 out of 25000 queries used.
35 Correct 5 ms 8336 KB Correct: 6433 out of 25000 queries used.
36 Correct 5 ms 8276 KB Correct: 6412 out of 25000 queries used.
37 Correct 5 ms 8276 KB Correct: 6426 out of 25000 queries used.
38 Correct 5 ms 8276 KB Correct: 6452 out of 25000 queries used.
39 Correct 5 ms 8276 KB Correct: 6430 out of 25000 queries used.
40 Correct 4 ms 8276 KB Correct: 6440 out of 25000 queries used.
41 Correct 5 ms 8248 KB Correct: 6438 out of 25000 queries used.
42 Correct 6 ms 8276 KB Correct: 6448 out of 25000 queries used.
43 Correct 5 ms 8148 KB Correct: 2989 out of 25000 queries used.
44 Correct 6 ms 8276 KB Correct: 6369 out of 25000 queries used.
45 Correct 5 ms 8276 KB Correct: 6401 out of 25000 queries used.
46 Correct 5 ms 8276 KB Correct: 6371 out of 25000 queries used.
47 Correct 5 ms 8276 KB Correct: 6432 out of 25000 queries used.
48 Correct 5 ms 8276 KB Correct: 6466 out of 25000 queries used.
49 Correct 6 ms 8276 KB Correct: 6461 out of 25000 queries used.
50 Correct 6 ms 8276 KB Correct: 6449 out of 25000 queries used.
51 Correct 6 ms 8276 KB Correct: 6450 out of 25000 queries used.
52 Correct 6 ms 8276 KB Correct: 6432 out of 25000 queries used.
53 Correct 6 ms 8276 KB Correct: 6719 out of 25000 queries used.
54 Correct 6 ms 8404 KB Correct: 16016 out of 25000 queries used.
55 Correct 7 ms 8276 KB Correct: 6448 out of 25000 queries used.
56 Correct 5 ms 8276 KB Correct: 6433 out of 25000 queries used.
57 Correct 5 ms 8276 KB Correct: 6719 out of 25000 queries used.
58 Correct 8 ms 8284 KB Correct: 6379 out of 25000 queries used.
59 Correct 7 ms 8276 KB Correct: 6410 out of 25000 queries used.
60 Correct 5 ms 8276 KB Correct: 6835 out of 25000 queries used.
61 Correct 5 ms 7764 KB Correct: 6771 out of 25000 queries used.
62 Correct 4 ms 7636 KB Correct: 5999 out of 25000 queries used.
63 Correct 4 ms 8148 KB Correct: 6059 out of 25000 queries used.
64 Correct 5 ms 7764 KB Correct: 6033 out of 25000 queries used.
65 Correct 5 ms 8020 KB Correct: 7906 out of 25000 queries used.
66 Correct 5 ms 8276 KB Correct: 6627 out of 25000 queries used.
67 Correct 5 ms 8276 KB Correct: 3687 out of 25000 queries used.
68 Correct 7 ms 8272 KB Correct: 16512 out of 25000 queries used.
69 Correct 6 ms 8404 KB Correct: 11367 out of 25000 queries used.
70 Correct 7 ms 8276 KB Correct: 12367 out of 25000 queries used.