Submission #964699

# Submission time Handle Problem Language Result Execution time Memory
964699 2024-04-17T11:01:59 Z 8pete8 City Mapping (NOI18_citymapping) C++17
0 / 100
10 ms 604 KB
#include "citymapping.h"
#include<iostream>
#include<stack>
#include<map>
#include<vector>
#include<string>
#include<unordered_map>
#include <queue>
#include<cstring>
#include<limits.h>
#include <cassert>
#include<cmath>
#include<set>
#include<algorithm>
#include <iomanip>
#include<numeric> //gcd(a,b)
#include<bitset>
#include <cstdlib> 
#include <cstdint>
using namespace std;
#define ll long long
#define f first
//#define endl "\n"
#define s second
#define pii pair<int,int>
#define ppii pair<int,pii>
#define vi vector<int>
#define pb push_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define F(n) for(int i=0;i<n;i++)
#define lb lower_bound
#define ub upper_bound
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
#pragma GCC optimize ("03,unroll-loops")
using namespace std;
#define int long long
//#define double long double
const int mxn=2e3,inf=1e18;
vector<int>on;
int sz[mxn+10],del[mxn+10],D[mxn+10],up[mxn+10];
vector<pair<pii,int>>e;
vector<pii>adj[mxn+10];
vector<int>von;
int cnt=0;
int n;
void getsz(int cur,int p){
	sz[cur]=1;
	cnt++;
	on.pb(cur);
	for(auto i:adj[cur]){
		if(del[i.f]||i.f==p)continue;
		up[i.f]=cur;
		getsz(i.f,cur);
		sz[cur]+=sz[i.f];
	}
}
int qnode,last;
void solve(int node){
	on.clear();
	cnt=0;
	getsz(node,-1);
	pii ed={inf,-1};
	if(on.size()==1){
		int y=get_distance(node,qnode);
		e.pb({{qnode,node},y});
		adj[node].pb({qnode,y});
		adj[qnode].pb({node,y});
		return;
	}
	for(auto i:on)ed=min(ed,{abs((cnt/2)-sz[i]),i});
	int x=get_distance(ed.s,qnode);
	if(D[qnode]==D[ed.s]+x){
		del[up[ed.s]]=1;
		for(int i=1;i<=n;i++)D[i]-=D[ed.s];
		solve(ed.s);
	}
	else{
		del[ed.s]=1;
		solve(node);
	}
}
void find_roads(int32_t N, int32_t q, int32_t A[], int32_t B[], int32_t W[]){
	n=N;
	srand(time(NULL));
	int st=rand()%n;
	st++;
	vector<pii>o;
	for(int i=1;i<=n;i++)if(i!=st)o.pb({get_distance(i,st),i});
	sort(all(o));
	for(auto i:o){
		qnode=i.s;
		for(int j=0;j<e.size();j++)del[j]=0;
		D[st]=0;
		for(auto i:o)D[i.s]=i.f;
		solve(st);
	}
	for(int i=0;i<e.size();i++)A[i]=e[i].f.f,B[i]=e[i].f.s,W[i]=e[i].s;
	return;
}

Compilation message

citymapping.cpp: In function 'void find_roads(int32_t, int32_t, int32_t*, int32_t*, int32_t*)':
citymapping.cpp:93:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<std::pair<long long int, long long int>, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   93 |   for(int j=0;j<e.size();j++)del[j]=0;
      |               ~^~~~~~~~~
citymapping.cpp:98:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<std::pair<long long int, long long int>, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   98 |  for(int i=0;i<e.size();i++)A[i]=e[i].f.f,B[i]=e[i].f.s,W[i]=e[i].s;
      |              ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 604 KB Reported list of edges differ from actual.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 604 KB Reported list of edges differ from actual.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 600 KB Reported list of edges differ from actual.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 600 KB Reported list of edges differ from actual.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 604 KB Reported list of edges differ from actual.
2 Halted 0 ms 0 KB -