답안 #1099511

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1099511 2024-10-11T13:53:00 Z NoMercy City Mapping (NOI18_citymapping) C++14
100 / 100
10 ms 856 KB
#include <bits/stdc++.h>
#include "citymapping.h"
using namespace std;

typedef long long ll;

const int MAXN = 1e3 + 100;

vector<int> g[MAXN], del(MAXN, 0);
ll d[MAXN][MAXN];
vector<array<int, 2>> ans;
int sz[MAXN], mx[MAXN];
 
void dfs (int si) {
	sz[si] = 1; 
	mx[si] = 0;
	for (auto v : g[si]) {
		if (del[v]) continue;
		dfs (v);
		sz[si] += sz[v];
		if(sz[v] > sz[mx[si]]) mx[si] = v;
	}
}
 
void find_roads (int N, int Q, int A[], int B[], int W[]) {
	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 (auto i : v) {
		// cout << i << "\n";
		for (int j = 0;j <= N + 1;j ++) {
			del[j] = 0;
		}
		int r = 1;
		while (true) {
			dfs(r);
			vector<int> path;
			path.push_back(r);
			while (mx[path.back()]) {
				path.push_back(mx[path.back()]);
			}
			if (path.size() == 1) {
				break;
			}
			// cout << path.back() << " " << i << "\n";
			ll x = d[1][path.back()] + d[1][i] - get_distance(path.back(), i);
			x /= 2;
			int j = 0;
			while (d[1][path[j]] != x) {
				j ++;
			}
			r = path[j]; 
			if (j + 1 < path.size()) {
				del[path[j + 1]] = 1;
			}
		}
		A[edg] = r; 
		B[edg] = i;
		W[edg ++] = d[1][i] - d[1][r];
		g[r].push_back(i);
	}
}

Compilation message

citymapping.cpp: In function 'void find_roads(int, int, int*, int*, int*)':
citymapping.cpp:59:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |    if (j + 1 < path.size()) {
      |        ~~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 604 KB Correct: 2695 out of 500000 queries used.
2 Correct 7 ms 604 KB Correct: 2428 out of 500000 queries used.
3 Correct 5 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 7 ms 604 KB Correct: 3397 out of 500000 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 604 KB Correct: 2695 out of 500000 queries used.
2 Correct 7 ms 604 KB Correct: 2428 out of 500000 queries used.
3 Correct 5 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 7 ms 604 KB Correct: 3397 out of 500000 queries used.
6 Correct 7 ms 608 KB Correct: 2009 out of 500000 queries used.
7 Correct 6 ms 580 KB Correct: 2063 out of 500000 queries used.
8 Correct 5 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.
# 결과 실행 시간 메모리 Grader output
1 Correct 8 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 10 ms 696 KB Correct: 2459 out of 12000 queries used.
4 Correct 8 ms 600 KB Correct: 2466 out of 12000 queries used.
5 Correct 7 ms 728 KB Correct: 2232 out of 12000 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 8 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 10 ms 696 KB Correct: 2459 out of 12000 queries used.
4 Correct 8 ms 600 KB Correct: 2466 out of 12000 queries used.
5 Correct 7 ms 728 KB Correct: 2232 out of 12000 queries used.
6 Correct 8 ms 572 KB Correct: 2473 out of 12000 queries used.
7 Correct 7 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 8 ms 604 KB Correct: 2235 out of 12000 queries used.
10 Correct 7 ms 604 KB Correct: 2302 out of 12000 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 604 KB Correct: 2695 out of 500000 queries used.
2 Correct 7 ms 604 KB Correct: 2428 out of 500000 queries used.
3 Correct 5 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 7 ms 604 KB Correct: 3397 out of 500000 queries used.
6 Correct 7 ms 608 KB Correct: 2009 out of 500000 queries used.
7 Correct 6 ms 580 KB Correct: 2063 out of 500000 queries used.
8 Correct 5 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 8 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 10 ms 696 KB Correct: 2459 out of 12000 queries used.
14 Correct 8 ms 600 KB Correct: 2466 out of 12000 queries used.
15 Correct 7 ms 728 KB Correct: 2232 out of 12000 queries used.
16 Correct 8 ms 572 KB Correct: 2473 out of 12000 queries used.
17 Correct 7 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 8 ms 604 KB Correct: 2235 out of 12000 queries used.
20 Correct 7 ms 604 KB Correct: 2302 out of 12000 queries used.
21 Correct 8 ms 604 KB Correct: 2502 out of 25000 queries used.
22 Correct 6 ms 856 KB Correct: 2071 out of 25000 queries used.
23 Correct 7 ms 604 KB Correct: 2284 out of 25000 queries used.
24 Correct 8 ms 604 KB Correct: 2036 out of 25000 queries used.
25 Correct 6 ms 604 KB Correct: 4436 out of 25000 queries used.
26 Correct 6 ms 672 KB Correct: 4358 out of 25000 queries used.
27 Correct 6 ms 580 KB Correct: 4307 out of 25000 queries used.
28 Correct 6 ms 604 KB Correct: 4417 out of 25000 queries used.
29 Correct 7 ms 604 KB Correct: 4502 out of 25000 queries used.
30 Correct 6 ms 600 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 600 KB Correct: 5158 out of 25000 queries used.
35 Correct 6 ms 604 KB Correct: 5100 out of 25000 queries used.
36 Correct 6 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 5 ms 604 KB Correct: 5102 out of 25000 queries used.
39 Correct 6 ms 600 KB Correct: 5135 out of 25000 queries used.
40 Correct 6 ms 604 KB Correct: 5168 out of 25000 queries used.
41 Correct 7 ms 676 KB Correct: 5124 out of 25000 queries used.
42 Correct 6 ms 604 KB Correct: 5203 out of 25000 queries used.
43 Correct 7 ms 604 KB Correct: 2087 out of 25000 queries used.
44 Correct 5 ms 588 KB Correct: 5116 out of 25000 queries used.
45 Correct 5 ms 600 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 672 KB Correct: 5179 out of 25000 queries used.
48 Correct 6 ms 668 KB Correct: 5135 out of 25000 queries used.
49 Correct 6 ms 600 KB Correct: 5091 out of 25000 queries used.
50 Correct 6 ms 604 KB Correct: 5105 out of 25000 queries used.
51 Correct 6 ms 600 KB Correct: 5099 out of 25000 queries used.
52 Correct 5 ms 604 KB Correct: 5128 out of 25000 queries used.
53 Correct 6 ms 676 KB Correct: 5144 out of 25000 queries used.
54 Correct 7 ms 600 KB Correct: 2333 out of 25000 queries used.
55 Correct 6 ms 604 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 5 ms 676 KB Correct: 5115 out of 25000 queries used.
59 Correct 6 ms 856 KB Correct: 5104 out of 25000 queries used.
60 Correct 6 ms 676 KB Correct: 3041 out of 25000 queries used.
61 Correct 7 ms 652 KB Correct: 3317 out of 25000 queries used.
62 Correct 6 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 656 KB Correct: 3103 out of 25000 queries used.
65 Correct 7 ms 608 KB Correct: 2067 out of 25000 queries used.
66 Correct 7 ms 604 KB Correct: 3228 out of 25000 queries used.
67 Correct 7 ms 600 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 684 KB Correct: 2451 out of 25000 queries used.
70 Correct 7 ms 604 KB Correct: 2414 out of 25000 queries used.