Submission #963476

# Submission time Handle Problem Language Result Execution time Memory
963476 2024-04-15T06:35:20 Z vjudge1 City Mapping (NOI18_citymapping) C++17
100 / 100
8 ms 856 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define ent "\n"

const int maxn = 1e3 + 100;
const ll INF = (ll)1e18 + 100;
const int inf = 1e9 + 100;
const int MOD = 1e9 + 7;
const int maxl = 30;
const int P = 31;

long long get_distance(int X, int Y);

int n;
vector<int> g[maxn];
int del[maxn];
ll d[maxn][maxn];
vector<pii> ans;
int sz[maxn];
int mx[maxn];

void get(int v){
	sz[v] = 1; mx[v] = 0;
	for(int to: g[v]){
		if(del[to]) continue;
		get(to);
		sz[v] += sz[to];
		if(sz[to] > sz[mx[v]]) mx[v] = to;
	}
}

void find_roads(int N, int Q, int A[], int B[], int W[]){
	n = N;
	vector<int> v;
	for(int i = 2; i <= n; i++){
		v.push_back(i);
		d[1][i] = get_distance(1, i);
	}
	sort(v.begin(), v.end(), [](int i, int j){
		return d[1][i] < d[1][j];
	});
	int edg = 0;
	for(int i: v){
		fill(del, del + n + 1, 0);
		int r = 1;
		while(true){
			get(r);
			vector<int> s;
			s.push_back(r);
			while(mx[s.back()]){
				s.push_back(mx[s.back()]);
			}
			if(s.size() == 1) break;
			ll x = d[1][s.back()] + d[1][i] - get_distance(s.back(), i);
			x /= 2; int j = 0;
			while(d[1][s[j]] != x) j++;
			r = s[j]; 
			if(j + 1 < s.size()) del[s[j+1]] = 1;
		}
		A[edg] = r; B[edg] = i;
		W[edg] = d[1][i] - d[1][r];
		edg++; g[r].push_back(i);
	}
}

Compilation message

citymapping.cpp: In function 'void find_roads(int, int, int*, int*, int*)':
citymapping.cpp:61:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |    if(j + 1 < s.size()) del[s[j+1]] = 1;
      |       ~~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 8 ms 604 KB Correct: 2695 out of 500000 queries used.
2 Correct 6 ms 604 KB Correct: 2428 out of 500000 queries used.
3 Correct 6 ms 604 KB Correct: 4527 out of 500000 queries used.
4 Correct 6 ms 604 KB Correct: 5523 out of 500000 queries used.
5 Correct 8 ms 600 KB Correct: 3397 out of 500000 queries used.
# Verdict Execution time Memory Grader output
1 Correct 8 ms 604 KB Correct: 2695 out of 500000 queries used.
2 Correct 6 ms 604 KB Correct: 2428 out of 500000 queries used.
3 Correct 6 ms 604 KB Correct: 4527 out of 500000 queries used.
4 Correct 6 ms 604 KB Correct: 5523 out of 500000 queries used.
5 Correct 8 ms 600 KB Correct: 3397 out of 500000 queries used.
6 Correct 7 ms 708 KB Correct: 2009 out of 500000 queries used.
7 Correct 6 ms 604 KB Correct: 2063 out of 500000 queries used.
8 Correct 6 ms 604 KB Correct: 4244 out of 500000 queries used.
9 Correct 6 ms 600 KB Correct: 5089 out of 500000 queries used.
10 Correct 7 ms 604 KB Correct: 3054 out of 500000 queries used.
# Verdict Execution time Memory Grader output
1 Correct 7 ms 604 KB Correct: 2082 out of 12000 queries used.
2 Correct 7 ms 604 KB Correct: 2321 out of 12000 queries used.
3 Correct 8 ms 604 KB Correct: 2459 out of 12000 queries used.
4 Correct 7 ms 604 KB Correct: 2466 out of 12000 queries used.
5 Correct 7 ms 604 KB Correct: 2232 out of 12000 queries used.
# Verdict Execution time Memory Grader output
1 Correct 7 ms 604 KB Correct: 2082 out of 12000 queries used.
2 Correct 7 ms 604 KB Correct: 2321 out of 12000 queries used.
3 Correct 8 ms 604 KB Correct: 2459 out of 12000 queries used.
4 Correct 7 ms 604 KB Correct: 2466 out of 12000 queries used.
5 Correct 7 ms 604 KB Correct: 2232 out of 12000 queries used.
6 Correct 8 ms 848 KB Correct: 2473 out of 12000 queries used.
7 Correct 8 ms 604 KB Correct: 2382 out of 12000 queries used.
8 Correct 7 ms 604 KB Correct: 2207 out of 12000 queries used.
9 Correct 7 ms 692 KB Correct: 2235 out of 12000 queries used.
10 Correct 7 ms 856 KB Correct: 2302 out of 12000 queries used.
# Verdict Execution time Memory Grader output
1 Correct 8 ms 604 KB Correct: 2695 out of 500000 queries used.
2 Correct 6 ms 604 KB Correct: 2428 out of 500000 queries used.
3 Correct 6 ms 604 KB Correct: 4527 out of 500000 queries used.
4 Correct 6 ms 604 KB Correct: 5523 out of 500000 queries used.
5 Correct 8 ms 600 KB Correct: 3397 out of 500000 queries used.
6 Correct 7 ms 708 KB Correct: 2009 out of 500000 queries used.
7 Correct 6 ms 604 KB Correct: 2063 out of 500000 queries used.
8 Correct 6 ms 604 KB Correct: 4244 out of 500000 queries used.
9 Correct 6 ms 600 KB Correct: 5089 out of 500000 queries used.
10 Correct 7 ms 604 KB Correct: 3054 out of 500000 queries used.
11 Correct 7 ms 604 KB Correct: 2082 out of 12000 queries used.
12 Correct 7 ms 604 KB Correct: 2321 out of 12000 queries used.
13 Correct 8 ms 604 KB Correct: 2459 out of 12000 queries used.
14 Correct 7 ms 604 KB Correct: 2466 out of 12000 queries used.
15 Correct 7 ms 604 KB Correct: 2232 out of 12000 queries used.
16 Correct 8 ms 848 KB Correct: 2473 out of 12000 queries used.
17 Correct 8 ms 604 KB Correct: 2382 out of 12000 queries used.
18 Correct 7 ms 604 KB Correct: 2207 out of 12000 queries used.
19 Correct 7 ms 692 KB Correct: 2235 out of 12000 queries used.
20 Correct 7 ms 856 KB Correct: 2302 out of 12000 queries used.
21 Correct 8 ms 600 KB Correct: 2502 out of 25000 queries used.
22 Correct 6 ms 604 KB Correct: 2071 out of 25000 queries used.
23 Correct 7 ms 604 KB Correct: 2284 out of 25000 queries used.
24 Correct 7 ms 672 KB Correct: 2036 out of 25000 queries used.
25 Correct 7 ms 604 KB Correct: 4436 out of 25000 queries used.
26 Correct 6 ms 600 KB Correct: 4358 out of 25000 queries used.
27 Correct 6 ms 604 KB Correct: 4307 out of 25000 queries used.
28 Correct 6 ms 604 KB Correct: 4417 out of 25000 queries used.
29 Correct 6 ms 604 KB Correct: 4502 out of 25000 queries used.
30 Correct 6 ms 604 KB Correct: 4442 out of 25000 queries used.
31 Correct 6 ms 604 KB Correct: 5151 out of 25000 queries used.
32 Correct 7 ms 604 KB Correct: 2223 out of 25000 queries used.
33 Correct 6 ms 604 KB Correct: 5083 out of 25000 queries used.
34 Correct 6 ms 652 KB Correct: 5158 out of 25000 queries used.
35 Correct 7 ms 600 KB Correct: 5100 out of 25000 queries used.
36 Correct 7 ms 604 KB Correct: 5118 out of 25000 queries used.
37 Correct 6 ms 604 KB Correct: 5144 out of 25000 queries used.
38 Correct 6 ms 604 KB Correct: 5102 out of 25000 queries used.
39 Correct 8 ms 604 KB Correct: 5135 out of 25000 queries used.
40 Correct 6 ms 600 KB Correct: 5168 out of 25000 queries used.
41 Correct 6 ms 600 KB Correct: 5124 out of 25000 queries used.
42 Correct 6 ms 600 KB Correct: 5203 out of 25000 queries used.
43 Correct 7 ms 604 KB Correct: 2087 out of 25000 queries used.
44 Correct 6 ms 648 KB Correct: 5116 out of 25000 queries used.
45 Correct 6 ms 604 KB Correct: 5090 out of 25000 queries used.
46 Correct 6 ms 604 KB Correct: 5068 out of 25000 queries used.
47 Correct 6 ms 856 KB Correct: 5179 out of 25000 queries used.
48 Correct 6 ms 856 KB Correct: 5135 out of 25000 queries used.
49 Correct 6 ms 604 KB Correct: 5091 out of 25000 queries used.
50 Correct 6 ms 652 KB Correct: 5105 out of 25000 queries used.
51 Correct 6 ms 604 KB Correct: 5099 out of 25000 queries used.
52 Correct 6 ms 604 KB Correct: 5128 out of 25000 queries used.
53 Correct 6 ms 604 KB Correct: 5144 out of 25000 queries used.
54 Correct 7 ms 604 KB Correct: 2333 out of 25000 queries used.
55 Correct 6 ms 648 KB Correct: 5196 out of 25000 queries used.
56 Correct 6 ms 600 KB Correct: 5141 out of 25000 queries used.
57 Correct 6 ms 604 KB Correct: 5125 out of 25000 queries used.
58 Correct 6 ms 604 KB Correct: 5115 out of 25000 queries used.
59 Correct 6 ms 604 KB Correct: 5104 out of 25000 queries used.
60 Correct 7 ms 604 KB Correct: 3041 out of 25000 queries used.
61 Correct 7 ms 644 KB Correct: 3317 out of 25000 queries used.
62 Correct 7 ms 604 KB Correct: 2917 out of 25000 queries used.
63 Correct 8 ms 604 KB Correct: 3317 out of 25000 queries used.
64 Correct 7 ms 664 KB Correct: 3103 out of 25000 queries used.
65 Correct 6 ms 604 KB Correct: 2067 out of 25000 queries used.
66 Correct 7 ms 600 KB Correct: 3228 out of 25000 queries used.
67 Correct 6 ms 604 KB Correct: 2018 out of 25000 queries used.
68 Correct 7 ms 604 KB Correct: 2394 out of 25000 queries used.
69 Correct 7 ms 604 KB Correct: 2451 out of 25000 queries used.
70 Correct 7 ms 604 KB Correct: 2414 out of 25000 queries used.