【USACO 2011】 道路和航线

本文介绍了如何解决USACO 2011竞赛中关于道路和航线的问题,采用的算法是SPFA结合SLF或LLL优化。提供了详细的代码实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

【题目链接】

              点击打开链接

【算法】

           SPFA + SLF / LLL 优化

【代码】

           

#include<bits/stdc++.h>
using namespace std;
#define MAXT 25000

int i,T,R,P,S,u,v,w;
int dist[MAXT+10],vis[MAXT+10];
vector<pair<int,int> > E[MAXT+10];

template <typename T> void read(T &x) {
		int f=1; char c = getchar(); x=0;
		for (; !isdigit(c); c = getchar()) { if (c=='-') f=-1; }
		for (; isdigit(c); c = getchar()) x=x*10+c-'0';
		x*=f;
}

inline void SPFA() {
		int i,x,to,cost;
		deque<int> q;
		for (i = 1; i <= T; i++) dist[i] = 2e9;
		dist[S] = 0; 
		q.push_back(S);
		while (!q.empty()) {
				x = q.front(); q.pop_front();
				vis[x] = 0;
				for (i = 0; i < E[x].size(); i
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值