답안 #836613

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
836613 2023-08-24T13:23:03 Z Liudas City Mapping (NOI18_citymapping) C++17
22 / 100
23 ms 632 KB
#include "citymapping.h"
#include <bits/stdc++.h>
using namespace std;
struct node{
	vector<int> childs;
	vector<int> dists;
};
void dfs(int head, int par, int dist, vector<node> &tree, vector<int> &good, int d){
	if((tree[head].childs.size() <= 2) && d < dist){
		good.push_back(head);
	}
	for(int i = 0; i < tree[head].childs.size(); i ++){
		if(tree[head].childs[i] == par)continue;
		dfs(tree[head].childs[i], head, dist, tree, good, d + tree[head].dists[i]);
	}
}
void find_roads(int N, int Q, int A[], int B[], int W[]) {
	vector<pair<long long, long long>> tree;
	vector<long long> init(N+5);
	int p = 0;
	for(int i = 1; i < N; i ++){
		tree.push_back({get_distance(1, i+1), i+1});
		init[i+1] = tree.back().first;
	}
	sort(tree.begin(), tree.end());
	vector<int> picks(N+20);
	picks[0] = -1e9;
	vector <long long> ends;
	ends.push_back(1);
	vector<node> arr(N + 20);
	for(auto [j, i] : tree){
		sort(ends.begin(), ends.end(), [&](long long a, long long b){return init[a] < init[b];});
		int t = get_distance(ends.back(), i);
		vector<int> good;
		dfs(ends.back(), -1, t, arr, good, 0);
		sort(good.begin(), good.end(), [&](long long a, long long b){return init[a] > init[b];});
		for(auto r : good){
			long long t = get_distance(r, i);
			if(init[i] == init[r] + t){
				A[p] = i;
				B[p] = r;
				W[p++] = t;
				picks[r]++;
				ends.push_back(i);
				arr[r].childs.push_back(i);
				arr[r].dists.push_back(t);
				arr[i].childs.push_back(r);
				arr[i].dists.push_back(t);
				break;
			}
		}
	}
	return;
}

Compilation message

citymapping.cpp: In function 'void dfs(int, int, int, std::vector<node>&, std::vector<int>&, int)':
citymapping.cpp:12:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |  for(int i = 0; i < tree[head].childs.size(); i ++){
      |                 ~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 584 KB Correct: 4157 out of 500000 queries used.
2 Correct 13 ms 596 KB Correct: 4072 out of 500000 queries used.
3 Correct 14 ms 468 KB Correct: 31822 out of 500000 queries used.
4 Correct 13 ms 468 KB Correct: 47490 out of 500000 queries used.
5 Correct 23 ms 468 KB Correct: 12042 out of 500000 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 584 KB Correct: 4157 out of 500000 queries used.
2 Correct 13 ms 596 KB Correct: 4072 out of 500000 queries used.
3 Correct 14 ms 468 KB Correct: 31822 out of 500000 queries used.
4 Correct 13 ms 468 KB Correct: 47490 out of 500000 queries used.
5 Correct 23 ms 468 KB Correct: 12042 out of 500000 queries used.
6 Incorrect 13 ms 596 KB Reported list of edges differ from actual.
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 596 KB Correct: 3141 out of 12000 queries used.
2 Correct 12 ms 628 KB Correct: 3524 out of 12000 queries used.
3 Correct 14 ms 632 KB Correct: 3804 out of 12000 queries used.
4 Correct 14 ms 596 KB Correct: 3768 out of 12000 queries used.
5 Correct 11 ms 596 KB Correct: 3408 out of 12000 queries used.
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 596 KB Correct: 3141 out of 12000 queries used.
2 Correct 12 ms 628 KB Correct: 3524 out of 12000 queries used.
3 Correct 14 ms 632 KB Correct: 3804 out of 12000 queries used.
4 Correct 14 ms 596 KB Correct: 3768 out of 12000 queries used.
5 Correct 11 ms 596 KB Correct: 3408 out of 12000 queries used.
6 Incorrect 18 ms 596 KB Reported list of edges differ from actual.
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 584 KB Correct: 4157 out of 500000 queries used.
2 Correct 13 ms 596 KB Correct: 4072 out of 500000 queries used.
3 Correct 14 ms 468 KB Correct: 31822 out of 500000 queries used.
4 Correct 13 ms 468 KB Correct: 47490 out of 500000 queries used.
5 Correct 23 ms 468 KB Correct: 12042 out of 500000 queries used.
6 Incorrect 13 ms 596 KB Reported list of edges differ from actual.
7 Halted 0 ms 0 KB -