Submission #961864

# Submission time Handle Problem Language Result Execution time Memory
961864 2024-04-12T15:07:06 Z vjudge1 City Mapping (NOI18_citymapping) C++17
100 / 100
15 ms 22104 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 block=400;
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++){
		for(int j=1;j<=n;j++)use[j]=0;
		build(1);
		int cur=1;
		int f=ord[i];
		ll d1=d[f];
		vector<int> P;
		bool was=0;
		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);
				was=1;
				// cout<<i-2<<" "<<vec[0]<<" "<<f<<" "<<d1<<"\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;
						vector<int> can;
						for(auto to:g[vec[i]]){
							if(use[to])continue;
							if(to!=big[vec[i]]){
								can.pb(to);
							}
						}
						if(can.empty())big[vec[i]]=0;
						else{
							big[vec[i]]=can[0];
						}
						for(int j=0;j<sz(vec);j++){
							if(i!=j)use[vec[j]]=1;
						}
					}
					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")
      | 
citymapping.cpp: In function 'void find_roads(int, int, int*, int*, int*)':
citymapping.cpp:108:12: warning: unused variable 'changed' [-Wunused-variable]
  108 |       bool changed=0;
      |            ^~~~~~~
citymapping.cpp:86:8: warning: variable 'was' set but not used [-Wunused-but-set-variable]
   86 |   bool was=0;
      |        ^~~
# Verdict Execution time Memory Grader output
1 Correct 12 ms 21848 KB Correct: 2695 out of 500000 queries used.
2 Correct 10 ms 21852 KB Correct: 2428 out of 500000 queries used.
3 Correct 9 ms 21836 KB Correct: 4527 out of 500000 queries used.
4 Correct 9 ms 21852 KB Correct: 5523 out of 500000 queries used.
5 Correct 11 ms 21908 KB Correct: 3397 out of 500000 queries used.
# Verdict Execution time Memory Grader output
1 Correct 12 ms 21848 KB Correct: 2695 out of 500000 queries used.
2 Correct 10 ms 21852 KB Correct: 2428 out of 500000 queries used.
3 Correct 9 ms 21836 KB Correct: 4527 out of 500000 queries used.
4 Correct 9 ms 21852 KB Correct: 5523 out of 500000 queries used.
5 Correct 11 ms 21908 KB Correct: 3397 out of 500000 queries used.
6 Correct 12 ms 21852 KB Correct: 2009 out of 500000 queries used.
7 Correct 11 ms 21852 KB Correct: 2063 out of 500000 queries used.
8 Correct 9 ms 21852 KB Correct: 4244 out of 500000 queries used.
9 Correct 9 ms 21872 KB Correct: 5089 out of 500000 queries used.
10 Correct 10 ms 21852 KB Correct: 3054 out of 500000 queries used.
# Verdict Execution time Memory Grader output
1 Correct 12 ms 21852 KB Correct: 2082 out of 12000 queries used.
2 Correct 12 ms 21852 KB Correct: 2321 out of 12000 queries used.
3 Correct 11 ms 21852 KB Correct: 2459 out of 12000 queries used.
4 Correct 15 ms 21852 KB Correct: 2466 out of 12000 queries used.
5 Correct 12 ms 21932 KB Correct: 2232 out of 12000 queries used.
# Verdict Execution time Memory Grader output
1 Correct 12 ms 21852 KB Correct: 2082 out of 12000 queries used.
2 Correct 12 ms 21852 KB Correct: 2321 out of 12000 queries used.
3 Correct 11 ms 21852 KB Correct: 2459 out of 12000 queries used.
4 Correct 15 ms 21852 KB Correct: 2466 out of 12000 queries used.
5 Correct 12 ms 21932 KB Correct: 2232 out of 12000 queries used.
6 Correct 12 ms 21848 KB Correct: 2473 out of 12000 queries used.
7 Correct 12 ms 21904 KB Correct: 2382 out of 12000 queries used.
8 Correct 12 ms 22104 KB Correct: 2207 out of 12000 queries used.
9 Correct 12 ms 21848 KB Correct: 2235 out of 12000 queries used.
10 Correct 12 ms 21852 KB Correct: 2302 out of 12000 queries used.
# Verdict Execution time Memory Grader output
1 Correct 12 ms 21848 KB Correct: 2695 out of 500000 queries used.
2 Correct 10 ms 21852 KB Correct: 2428 out of 500000 queries used.
3 Correct 9 ms 21836 KB Correct: 4527 out of 500000 queries used.
4 Correct 9 ms 21852 KB Correct: 5523 out of 500000 queries used.
5 Correct 11 ms 21908 KB Correct: 3397 out of 500000 queries used.
6 Correct 12 ms 21852 KB Correct: 2009 out of 500000 queries used.
7 Correct 11 ms 21852 KB Correct: 2063 out of 500000 queries used.
8 Correct 9 ms 21852 KB Correct: 4244 out of 500000 queries used.
9 Correct 9 ms 21872 KB Correct: 5089 out of 500000 queries used.
10 Correct 10 ms 21852 KB Correct: 3054 out of 500000 queries used.
11 Correct 12 ms 21852 KB Correct: 2082 out of 12000 queries used.
12 Correct 12 ms 21852 KB Correct: 2321 out of 12000 queries used.
13 Correct 11 ms 21852 KB Correct: 2459 out of 12000 queries used.
14 Correct 15 ms 21852 KB Correct: 2466 out of 12000 queries used.
15 Correct 12 ms 21932 KB Correct: 2232 out of 12000 queries used.
16 Correct 12 ms 21848 KB Correct: 2473 out of 12000 queries used.
17 Correct 12 ms 21904 KB Correct: 2382 out of 12000 queries used.
18 Correct 12 ms 22104 KB Correct: 2207 out of 12000 queries used.
19 Correct 12 ms 21848 KB Correct: 2235 out of 12000 queries used.
20 Correct 12 ms 21852 KB Correct: 2302 out of 12000 queries used.
21 Correct 12 ms 21848 KB Correct: 2502 out of 25000 queries used.
22 Correct 11 ms 21848 KB Correct: 2071 out of 25000 queries used.
23 Correct 10 ms 21900 KB Correct: 2284 out of 25000 queries used.
24 Correct 11 ms 22104 KB Correct: 2036 out of 25000 queries used.
25 Correct 9 ms 21852 KB Correct: 4496 out of 25000 queries used.
26 Correct 9 ms 21852 KB Correct: 4358 out of 25000 queries used.
27 Correct 9 ms 21876 KB Correct: 4324 out of 25000 queries used.
28 Correct 9 ms 21720 KB Correct: 4417 out of 25000 queries used.
29 Correct 9 ms 21852 KB Correct: 4502 out of 25000 queries used.
30 Correct 9 ms 21852 KB Correct: 4442 out of 25000 queries used.
31 Correct 10 ms 21852 KB Correct: 5151 out of 25000 queries used.
32 Correct 12 ms 21936 KB Correct: 2223 out of 25000 queries used.
33 Correct 11 ms 21900 KB Correct: 5083 out of 25000 queries used.
34 Correct 12 ms 21720 KB Correct: 5158 out of 25000 queries used.
35 Correct 10 ms 21724 KB Correct: 5100 out of 25000 queries used.
36 Correct 9 ms 21852 KB Correct: 5118 out of 25000 queries used.
37 Correct 12 ms 21852 KB Correct: 5144 out of 25000 queries used.
38 Correct 9 ms 21688 KB Correct: 5102 out of 25000 queries used.
39 Correct 9 ms 21852 KB Correct: 5126 out of 25000 queries used.
40 Correct 9 ms 21772 KB Correct: 5168 out of 25000 queries used.
41 Correct 9 ms 21852 KB Correct: 5124 out of 25000 queries used.
42 Correct 12 ms 21868 KB Correct: 5203 out of 25000 queries used.
43 Correct 12 ms 21848 KB Correct: 2087 out of 25000 queries used.
44 Correct 9 ms 21852 KB Correct: 5116 out of 25000 queries used.
45 Correct 9 ms 21848 KB Correct: 5090 out of 25000 queries used.
46 Correct 9 ms 21852 KB Correct: 5068 out of 25000 queries used.
47 Correct 9 ms 21848 KB Correct: 5179 out of 25000 queries used.
48 Correct 9 ms 21852 KB Correct: 5135 out of 25000 queries used.
49 Correct 9 ms 21852 KB Correct: 5091 out of 25000 queries used.
50 Correct 9 ms 21852 KB Correct: 5105 out of 25000 queries used.
51 Correct 9 ms 21852 KB Correct: 5099 out of 25000 queries used.
52 Correct 9 ms 21876 KB Correct: 5128 out of 25000 queries used.
53 Correct 11 ms 21848 KB Correct: 5144 out of 25000 queries used.
54 Correct 11 ms 21852 KB Correct: 2333 out of 25000 queries used.
55 Correct 10 ms 21720 KB Correct: 5196 out of 25000 queries used.
56 Correct 12 ms 21868 KB Correct: 5141 out of 25000 queries used.
57 Correct 10 ms 21852 KB Correct: 5125 out of 25000 queries used.
58 Correct 9 ms 21852 KB Correct: 5115 out of 25000 queries used.
59 Correct 9 ms 21852 KB Correct: 5105 out of 25000 queries used.
60 Correct 10 ms 21848 KB Correct: 3041 out of 25000 queries used.
61 Correct 11 ms 21876 KB Correct: 3317 out of 25000 queries used.
62 Correct 11 ms 21848 KB Correct: 2917 out of 25000 queries used.
63 Correct 11 ms 21852 KB Correct: 3317 out of 25000 queries used.
64 Correct 10 ms 21876 KB Correct: 3103 out of 25000 queries used.
65 Correct 11 ms 21852 KB Correct: 2067 out of 25000 queries used.
66 Correct 11 ms 21728 KB Correct: 3228 out of 25000 queries used.
67 Correct 10 ms 21852 KB Correct: 2018 out of 25000 queries used.
68 Correct 12 ms 21864 KB Correct: 2394 out of 25000 queries used.
69 Correct 11 ms 21852 KB Correct: 2451 out of 25000 queries used.
70 Correct 12 ms 21848 KB Correct: 2414 out of 25000 queries used.