답안 #674893

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
674893 2022-12-26T13:19:00 Z QwertyPi City Mapping (NOI18_citymapping) C++14
0 / 100
6 ms 1104 KB
#include "citymapping.h"

#include <bits/stdc++.h>

using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

struct edge{
	int u, v, w;
};
vector<edge> E;

const int MAXN = 1e3 + 11;
long long d[MAXN];
bool done[MAXN];
void solve(vector<int> v){
	if(v.size() == 1) return;
	for(auto i : v) done[i] = false;
	int id = rng() % v.size();
	int rt = v[id]; d[rt] = 0; done[rt] = true;
	for(auto i : v){
		if(i != rt) d[i] = get_distance(rt, i);
	}
	for(int tr = 0; tr < 3; tr++){
		int ch = -1;
		for(auto i : v){
			if(!done[i] && (ch == -1 || d[ch] > d[i])) ch = i;
		}
		if(ch == -1) break; done[ch] = true; 
		E.push_back({rt, ch, d[ch]});
		vector<long long> d2(MAXN);
		vector<int> sub_tree {ch};
		for(auto i : v){
			if(!done[i] && i != ch) {
				if(tr < 1) d2[i] = get_distance(ch, i);
				if(d2[i] <= d[i]) sub_tree.push_back(i), done[i] = true;
			}
		}
		solve(sub_tree);
	}
}

void find_roads(int N, int Q, int A[], int B[], int W[]) {
	vector<int> v;
	for(int i = 1; i <= N; i++){
		v.push_back(i);
	}
	solve(v);
	for(int i = 0; i < E.size(); i++){
		A[i] = E[i].u, B[i] = E[i].v, W[i] = E[i].w;
	}
	return;
}

Compilation message

citymapping.cpp: In function 'void solve(std::vector<int>)':
citymapping.cpp:30:3: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   30 |   if(ch == -1) break; done[ch] = true;
      |   ^~
citymapping.cpp:30:23: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   30 |   if(ch == -1) break; done[ch] = true;
      |                       ^~~~
citymapping.cpp:31:28: warning: narrowing conversion of 'd[ch]' from 'long long int' to 'int' [-Wnarrowing]
   31 |   E.push_back({rt, ch, d[ch]});
      |                        ~~~~^
citymapping.cpp: In function 'void find_roads(int, int, int*, int*, int*)':
citymapping.cpp:50:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<edge>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |  for(int i = 0; i < E.size(); i++){
      |                 ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 596 KB Correct: 21857 out of 500000 queries used.
2 Incorrect 6 ms 1104 KB Reported list of edges differ from actual.
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 596 KB Correct: 21857 out of 500000 queries used.
2 Incorrect 6 ms 1104 KB Reported list of edges differ from actual.
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 596 KB Too many calls to get_distance().
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 596 KB Too many calls to get_distance().
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 596 KB Correct: 21857 out of 500000 queries used.
2 Incorrect 6 ms 1104 KB Reported list of edges differ from actual.
3 Halted 0 ms 0 KB -