Submission #538957

# Submission time Handle Problem Language Result Execution time Memory
538957 2022-03-18T05:49:21 Z ac2hu City Mapping (NOI18_citymapping) C++14
9 / 100
198 ms 63072 KB
#include<bits/stdc++.h>
#include "citymapping.h"
using namespace std;
#define ll long long 
const ll N = 1e3 + 1;
long long dist[N][N];
ll n;
ll par[N];
long long gd(ll x,ll y){
	if(dist[x][y] != -1) return dist[x][y];
	long long temp = get_distance(x + 1, y + 1);
	dist[x][y] = temp;
	dist[y][x] = temp;
	return temp;
}
bool inpath(ll a,ll b, ll c){// check if c lies on a - b
	return gd(a, c) + gd(c, b) == gd(a, b);
}
void dfs(ll r,ll p, set<ll> temp){
	par[r] = p;
	if(temp.size() == 0)
		return;
	vector<pair<long long,ll>> tt;
	for(ll j : temp){
		tt.push_back({gd(r, j), j});
	}
	sort(tt.begin(),tt.end());
	while(tt.size() > 3)
		tt.pop_back();
	while(tt.size() > 1 && inpath(r, tt[1].second, tt[0].second)){
		tt.erase(tt.begin() + 1);
	}
	for(ll al = 0;al<2;al++){
		if(tt.size() > 2 && inpath(r, tt[2].second, tt[al].second)){
			tt.erase(tt.begin() + 2);
		}
	}
	for(ll al = 0;al<tt.size();al++){
		temp.erase(temp.find(tt[al].second));
	}
	// Only children are in tt
	vector<set<ll>> hold(tt.size());
	for(auto e : temp){
		for(ll i = 0;i<tt.size();i++){
			if(inpath(r, e , tt[i].second)){
				hold[i].insert(e);
				break;
			}
		}
	}
	for(ll i = 0;i<tt.size();i++){
		dfs(tt[i].second, r , hold[i]);
	}
}
void find_roads(int N, int Q, int A[], int B[], int W[]) {
	n = N;
	for(ll i = 0;i<N;i++){
		for(ll j = 0;j<N;j++){
			dist[i][j] = -1;
		}
	}
	ll r = 0;
	set<ll> temp;
	for(ll i = 0;i<n;i++){
		if(r == i)continue;
		temp.insert(i);
	}
	// vector<array<int,3>> edges;
	dfs(r, -1, temp);
	vector<array<ll,3>> edges;
	int p1 = 0;
	for(ll i = 0;i<n;i++){
		if(i != r){
			edges.push_back({i + 1, par[i] + 1, (ll)gd(i,par[i])});
		}
	}
	for(ll i = 0;i<n-1;i++){
		A[i] = edges[i][0], B[i] = edges[i][1], W[i] = edges[i][2];
	}
	return;
}

Compilation message

citymapping.cpp: In function 'void dfs(long long int, long long int, std::set<long long int>)':
citymapping.cpp:38:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |  for(ll al = 0;al<tt.size();al++){
      |                ~~^~~~~~~~~~
citymapping.cpp:44:17: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |   for(ll i = 0;i<tt.size();i++){
      |                ~^~~~~~~~~~
citymapping.cpp:51:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |  for(ll i = 0;i<tt.size();i++){
      |               ~^~~~~~~~~~
citymapping.cpp: In function 'void find_roads(int, int, int*, int*, int*)':
citymapping.cpp:71:6: warning: unused variable 'p1' [-Wunused-variable]
   71 |  int p1 = 0;
      |      ^~
# Verdict Execution time Memory Grader output
1 Correct 104 ms 25164 KB Correct: 251481 out of 500000 queries used.
2 Correct 96 ms 30996 KB Correct: 308832 out of 500000 queries used.
3 Correct 12 ms 9556 KB Correct: 27160 out of 500000 queries used.
4 Correct 10 ms 9172 KB Correct: 21473 out of 500000 queries used.
5 Correct 18 ms 10452 KB Correct: 43091 out of 500000 queries used.
# Verdict Execution time Memory Grader output
1 Correct 104 ms 25164 KB Correct: 251481 out of 500000 queries used.
2 Correct 96 ms 30996 KB Correct: 308832 out of 500000 queries used.
3 Correct 12 ms 9556 KB Correct: 27160 out of 500000 queries used.
4 Correct 10 ms 9172 KB Correct: 21473 out of 500000 queries used.
5 Correct 18 ms 10452 KB Correct: 43091 out of 500000 queries used.
6 Correct 198 ms 63072 KB Correct: 479862 out of 500000 queries used.
7 Incorrect 91 ms 33280 KB Reported list of edges differ from actual.
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 9172 KB Too many calls to get_distance().
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 9172 KB Too many calls to get_distance().
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 104 ms 25164 KB Correct: 251481 out of 500000 queries used.
2 Correct 96 ms 30996 KB Correct: 308832 out of 500000 queries used.
3 Correct 12 ms 9556 KB Correct: 27160 out of 500000 queries used.
4 Correct 10 ms 9172 KB Correct: 21473 out of 500000 queries used.
5 Correct 18 ms 10452 KB Correct: 43091 out of 500000 queries used.
6 Correct 198 ms 63072 KB Correct: 479862 out of 500000 queries used.
7 Incorrect 91 ms 33280 KB Reported list of edges differ from actual.
8 Halted 0 ms 0 KB -