跳到正文

题解

P9659 Shortest Path Fast Algorithm 题解

OccDreamer约 4 分钟
原文
文章信息与版本

文章信息

发布
2023年9月26日
收录
2026年7月24日
更新
2026年11月12日
篇幅
约 4 分钟
获赞
15
题目
P9659

版本

  1. v1当前

考虑每次入队一个点之后这一个点在优先队列中的权值知道它弹出来都不会变化。

怎么利用这个性质呢?

考虑现在如果有 44 个点 1,2,3,41,2,3,4,如果我们连边 (1,2,v1)(1,2,v_1),(1,3,1)(1,3,1),(3,2,1)(3,2,1),(3,4,v2)(3,4,v_2),(2,4,1)(2,4,1)。

其中 v1,v2v_1,v_2 都是很大的数,且 v2<v12v_2 < \dfrac{v_1}{2}。

那么我们可以做到弹堆顺序为 1,3,4,2,41,3,4,2,4,你会发现在这一个结构中 44 会被弹出两次。

那么如果我们能构造出 1616 个这样的结构,那么我们就可以使得弹出次数 ≥k=105\geq k=10^5。

类似于上述构造方法构造即可,需要注意下点的弹出顺序之类的。

代码中的 a,b,c,da,b,c,d 可以看做对应一个结构中的 1,2,3,41,2,3,4。

C++
//code by Emissary
#include<bits/stdc++.h>

#define fi first
#define se second
#define vc vector
#define db double
#define ll long long
#define mk make_pair
#define pb push_back
#define PI pair<int,int>
#define ull unsigned long long
#define err cerr << "   -_-   " << endl
#define debug cerr << " ------------------- " << endl

#define input(x) freopen(#x".in","r",stdin)
#define output(x) freopen(#x".out","w",stdout)

#define NO puts("No")
#define YES puts("Yes")

//#define int long long

using namespace std;

namespace IO{
	inline int read(){
		int X=0, W=0; char ch=getchar();
		while(!isdigit(ch)) W|=ch=='-', ch=getchar();
		while(isdigit(ch)) X=(X<<1)+(X<<3)+(ch^48), ch=getchar();
		return W?-X:X;
	}
	inline void write(int x){
		if(x<0) x=-x, putchar('-');
		if(x>9) write(x/10);
		putchar(x%10+'0');
	}
	inline void sprint(int x){write(x), putchar(32);}
	inline void eprint(int x){write(x), putchar(10);}
}using namespace IO;

const int inf = 1e6;

signed main(){
	freopen("SPFA.in","w",stdout);
	cout << 100 << ' ' << 16*5 << endl;
	int las=1, now=1e6;
	for(int i=1;i<=16;++i){
		int a=las, b=a+1, c=b+1, d=c+1;
		now--;
		cout << a << ' ' << b << ' ' << now << endl;
		now>>=1; now-=5;
		cout << a << ' ' << c << ' ' << 1 << endl;
		cout << c << ' ' << b << ' ' << 1 << endl;
		cout << c << ' ' << d << ' ' << now << endl;
		cout << b << ' ' << d << ' ' << 1 << endl;
		las=d;
	}
	return 0;
}