Submission #961830

# Submission time Handle Problem Language Result Execution time Memory
961830 2024-04-12T14:34:45 Z vjudge1 City Mapping (NOI18_citymapping) C++17
0 / 100
14 ms 19804 KB
#include <bits/stdc++.h>
 
#pragma optimize("Ofast")
#pragma target("avx2")
 
using namespace std;
 
#define ll long long
#define ld long double
#define pb push_back
#define pf push_front
#define pii pair<int,int>
#define all(v) v.begin(),v.end()
#define F first
#define S second
#define mem(a,i) memset(a,i,sizeof(a))
#define sz(s) (int)s.size()
#define y1 yy
#define ppb pop_back
#define lb lower_bound
#define ub upper_bound
#define gcd(a,b) __gcd(a,b)
#define in insert
// #define int ll
 
const int MAX=5e5+5;
const int B=90;
const int N=105;
const int block=400;
const int maxB=MAX/B+10;
const ll inf=2e18;  
const int mod=998244353;
const int mod1=1e9+9;
const ld eps=1e-9;
 
int dx[8]={1,0,-1,0,1,-1,-1,1};
int dy[8]={0,1,0,-1,1,-1,1,-1};
 
int binpow(int a,int n){
  if(!n)return 1;
  if(n%2==1)return a*binpow(a,n-1)%mod;
  int k=binpow(a,n/2);
  return k*k%mod;
}

#include "citymapping.h"

vector<int> g[MAX];
int use[MAX];
ll d[MAX];
int ord[MAX];
int n;

bool cmp(int x,int y){
	return d[x]<d[y];
}

int s[MAX];
int big[MAX];

void build(int v,int p=-1){
	s[v]=1;
	big[v]=0;
	for(auto to:g[v]){
		if(to==p)continue;
		build(to,v);
		if(s[to]>s[big[v]])big[v]=to;
		s[v]+=s[to];
	}
}

void find_roads(int N, int Q, int A[], int B[], int W[]) {
	n=N;

	for(int i=2;i<=n;i++){
		ord[i]=i;
		d[i]=get_distance(1,i);
	}

	sort(ord+2,ord+n+1,cmp);

	for(int i=2;i<=n;i++){
		// cout<<i<<" "<<ord[i]<<"\n";
		build(1);
		int cur=1;
		int f=ord[i];
		ll d1=d[f];
		for(int j=0;j<=10;j++){
			vector<int> vec;
			int curv=cur;
			while(curv){
				vec.pb(curv);
				curv=big[curv];
			}
			if(sz(vec)==1){
				A[i-2]=vec[0];
				B[i-2]=f;
				W[i-2]=d1;
				g[vec[0]].pb(f);
				// cout<<i-2<<" "<<vec[0]<<" "<<d1<<" "<<f<<"\n";
				break;
			}
			ll d2=get_distance(vec.back(),f);
			ll dpr=(d1+d2-(d[vec.back()]-d[vec[0]]))/2;
			for(int i=0;i<sz(vec);i++){
				if(d[f]==dpr+d[vec[i]]){
					{
						bool changed=0;
						for(auto to:g[vec[i]]){
							if(to!=big[vec[i]]){
								big[vec[i]]=to;
								changed=1;
							}
						}
						if(!changed)big[vec[i]]=0;
					}
					d1=dpr;
					cur=vec[i];
					break;
				}
			}
		}
	}
	
	return;
}

Compilation message

citymapping.cpp:3: warning: ignoring '#pragma optimize ' [-Wunknown-pragmas]
    3 | #pragma optimize("Ofast")
      | 
citymapping.cpp:4: warning: ignoring '#pragma target ' [-Wunknown-pragmas]
    4 | #pragma target("avx2")
      |
# Verdict Execution time Memory Grader output
1 Incorrect 14 ms 19804 KB Reported list of edges differ from actual.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 14 ms 19804 KB Reported list of edges differ from actual.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 19804 KB Reported list of edges differ from actual.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 19804 KB Reported list of edges differ from actual.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 14 ms 19804 KB Reported list of edges differ from actual.
2 Halted 0 ms 0 KB -