Submission #964667

# Submission time Handle Problem Language Result Execution time Memory
964667 2024-04-17T09:54:04 Z 8pete8 City Mapping (NOI18_citymapping) C++17
25 / 100
208 ms 868 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];
vector<pair<pii,int>>e;
vector<pii>adj[mxn+10];
vector<int>von;
int cnt=0;
void getsz(int cur,int p){
	sz[cur]=1;
	cnt++;
	for(auto i:adj[cur]){
		if(del[i.s]||i.f==p)continue;
		on.pb(i.s);
		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.empty()){
		if(last==inf)last=get_distance(node,qnode);
		e.pb({{node,qnode},last});
		adj[node].pb({qnode,e.size()-1});
		adj[qnode].pb({node,e.size()-1});
		return;
	}
	for(auto i:on){
		if(sz[e[i].f.f]>sz[e[i].f.s])swap(e[i].f.f,e[i].f.s);
		ed=min(ed,{abs(sz[e[i].f.f]-cnt+sz[e[i].f.s]),i});
	}
	del[ed.s]=1;
	int x=get_distance(e[ed.s].f.f,qnode),y=get_distance(e[ed.s].f.s,qnode);
	last=min(x,y);
	if(x<y)solve(e[ed.s].f.f);
	else solve(e[ed.s].f.s);
}
void find_roads(int32_t n, int32_t q, int32_t A[], int32_t B[], int32_t W[]){
	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;
		last=inf;
		for(int j=0;j<e.size();j++)del[j]=0;
		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:89: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]
   89 |   for(int j=0;j<e.size();j++)del[j]=0;
      |               ~^~~~~~~~~
citymapping.cpp:92: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]
   92 |  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 Correct 15 ms 600 KB Correct: 16957 out of 500000 queries used.
2 Correct 208 ms 736 KB Correct: 194654 out of 500000 queries used.
3 Correct 49 ms 696 KB Correct: 29749 out of 500000 queries used.
4 Correct 47 ms 720 KB Correct: 29895 out of 500000 queries used.
5 Correct 26 ms 728 KB Correct: 20813 out of 500000 queries used.
# Verdict Execution time Memory Grader output
1 Correct 15 ms 600 KB Correct: 16957 out of 500000 queries used.
2 Correct 208 ms 736 KB Correct: 194654 out of 500000 queries used.
3 Correct 49 ms 696 KB Correct: 29749 out of 500000 queries used.
4 Correct 47 ms 720 KB Correct: 29895 out of 500000 queries used.
5 Correct 26 ms 728 KB Correct: 20813 out of 500000 queries used.
6 Correct 16 ms 796 KB Correct: 16892 out of 500000 queries used.
7 Correct 24 ms 800 KB Correct: 19284 out of 500000 queries used.
8 Correct 61 ms 740 KB Correct: 31474 out of 500000 queries used.
9 Correct 50 ms 756 KB Correct: 27772 out of 500000 queries used.
10 Correct 28 ms 868 KB Correct: 19769 out of 500000 queries used.
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 604 KB Too many calls to get_distance().
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 604 KB Too many calls to get_distance().
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 15 ms 600 KB Correct: 16957 out of 500000 queries used.
2 Correct 208 ms 736 KB Correct: 194654 out of 500000 queries used.
3 Correct 49 ms 696 KB Correct: 29749 out of 500000 queries used.
4 Correct 47 ms 720 KB Correct: 29895 out of 500000 queries used.
5 Correct 26 ms 728 KB Correct: 20813 out of 500000 queries used.
6 Correct 16 ms 796 KB Correct: 16892 out of 500000 queries used.
7 Correct 24 ms 800 KB Correct: 19284 out of 500000 queries used.
8 Correct 61 ms 740 KB Correct: 31474 out of 500000 queries used.
9 Correct 50 ms 756 KB Correct: 27772 out of 500000 queries used.
10 Correct 28 ms 868 KB Correct: 19769 out of 500000 queries used.
11 Incorrect 9 ms 604 KB Too many calls to get_distance().
12 Halted 0 ms 0 KB -