Submission #1064667

# Submission time Handle Problem Language Result Execution time Memory
1064667 2024-08-18T16:39:03 Z Luvidi City Mapping (NOI18_citymapping) C++17
32 / 100
2 ms 724 KB
#include <bits/stdc++.h>
#include "citymapping.h"
using namespace std;

#define ll long long
#define pb push_back
#define fs first
#define sc second
#define pll pair<ll,ll>

int *a,*b,*w,n,cnt;
vector<int> ch[1001];
pll r[1001];

void solve(int v){
	if(ch[v].empty())return;
	ll dist[n+1];
	pll fr;
	dist[v]=0;
	for(int i:ch[v]){
		dist[i]=get_distance(i,v);
		fr=max(fr,{dist[i],i});
	}
	int x=fr.sc;
	ll dist2[n+1];
	vector<pll> pt;
	r[v]={1e18,1e18};
	for(int i:ch[v]){
		dist2[i]=get_distance(i,x);
		ll d=(dist[x]+dist[i]-dist2[i])/2,d2=(dist[i]+dist2[i]-dist[x])/2;
		if(!d2){
			r[i]={1e18,1e18};
			pt.pb({dist[i],i});
		}
	}
	pt.pb({0,v});
	sort(pt.begin(),pt.end());
	for(int i=1;i<pt.size();i++){
		a[cnt]=pt[i-1].sc;
		b[cnt]=pt[i].sc;
		w[cnt]=dist[b[cnt]]-dist[a[cnt]];
		cnt++;
	}

	for(int i:ch[v])if(i!=x){
		ll d=(dist[x]+dist[i]-dist2[i])/2,d2=(dist[i]+dist2[i]-dist[x])/2;
		if(!d2)continue;
		for(auto[xx,j]:pt){
			if(dist[j]==d){
				r[j]=min(r[j],{dist[i],i});
			}
		}
	}

	for(int i:ch[v])if(i!=x){
		ll d=(dist[x]+dist[i]-dist2[i])/2,d2=(dist[i]+dist2[i]-dist[x])/2;
		if(!d2)continue;
		for(auto[xx,j]:pt){
			if(dist[j]==d){
				int k=r[j].sc;
				if(k!=i)ch[k].pb(i);
			}
		}
	}
	for(int i=0;i<pt.size();i++){
		int j=pt[i].sc;
		if(r[j].sc<=n){
			a[cnt]=j;
			b[cnt]=r[j].sc;
			w[cnt]=dist[r[j].sc]-dist[j];
			cnt++;
			solve(r[j].sc);
		}
	}	
}

void find_roads(int N, int Q, int A[], int B[], int W[]) {
	a=A;
	b=B;
	w=W;
	n=N;
	for(int i=2;i<=n;i++)ch[1].pb(i);
	solve(1);
}

Compilation message

citymapping.cpp: In function 'void solve(int)':
citymapping.cpp:30:6: warning: unused variable 'd' [-Wunused-variable]
   30 |   ll d=(dist[x]+dist[i]-dist2[i])/2,d2=(dist[i]+dist2[i]-dist[x])/2;
      |      ^
citymapping.cpp:38:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |  for(int i=1;i<pt.size();i++){
      |              ~^~~~~~~~~~
citymapping.cpp:65:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |  for(int i=0;i<pt.size();i++){
      |              ~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Correct: 2916 out of 500000 queries used.
2 Correct 2 ms 604 KB Correct: 2226 out of 500000 queries used.
3 Correct 2 ms 604 KB Correct: 6284 out of 500000 queries used.
4 Incorrect 2 ms 604 KB Reported list of edges differ from actual.
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Correct: 2916 out of 500000 queries used.
2 Correct 2 ms 604 KB Correct: 2226 out of 500000 queries used.
3 Correct 2 ms 604 KB Correct: 6284 out of 500000 queries used.
4 Incorrect 2 ms 604 KB Reported list of edges differ from actual.
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Correct: 2120 out of 12000 queries used.
2 Correct 1 ms 724 KB Correct: 2422 out of 12000 queries used.
3 Correct 1 ms 504 KB Correct: 2628 out of 12000 queries used.
4 Correct 1 ms 604 KB Correct: 2616 out of 12000 queries used.
5 Correct 2 ms 604 KB Correct: 2324 out of 12000 queries used.
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Correct: 2120 out of 12000 queries used.
2 Correct 1 ms 724 KB Correct: 2422 out of 12000 queries used.
3 Correct 1 ms 504 KB Correct: 2628 out of 12000 queries used.
4 Correct 1 ms 604 KB Correct: 2616 out of 12000 queries used.
5 Correct 2 ms 604 KB Correct: 2324 out of 12000 queries used.
6 Correct 2 ms 604 KB Correct: 2936 out of 12000 queries used.
7 Correct 2 ms 604 KB Correct: 2764 out of 12000 queries used.
8 Correct 1 ms 604 KB Correct: 2390 out of 12000 queries used.
9 Correct 2 ms 604 KB Correct: 2446 out of 12000 queries used.
10 Correct 2 ms 604 KB Correct: 2610 out of 12000 queries used.
# Verdict Execution time Memory Grader output
1 Correct 1 ms 600 KB Correct: 2916 out of 500000 queries used.
2 Correct 2 ms 604 KB Correct: 2226 out of 500000 queries used.
3 Correct 2 ms 604 KB Correct: 6284 out of 500000 queries used.
4 Incorrect 2 ms 604 KB Reported list of edges differ from actual.
5 Halted 0 ms 0 KB -