复赛准备 - 最短路径问题(dijkstra)

本文深入探讨了最短路径问题中的Dijkstra算法,详细解释了算法原理,并提供了C++实现代码示例,帮助读者理解并掌握该算法的应用。

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

#include "iostream"
#include "vector"
#include "cmath"
#include "queue"
using namespace std;

const int N = 1e3;
const double INF = 1e10;

struct dist{
	int x;
	double l;
};

priority_queue<dist> qu;

bool operator < (const dist d1,const dist d2){
	return d1.l > d2.l;
}

struct edge{
	int to;//指向哪个点 
	double w;//权值:长度 
};


vector<edge> graph[N];

struct node{
	int x,y;
}nodes[N]; 

int n,m,s,t;//n个节点,m条边 

double dis[N];
int flag[N];


void addEdge(int from,int to);
void dijkstra(int x);

int main(){
	cin>>n;
	int x,y;
	for(int i=1;i<=n;i++){
		cin>>x>>y;
		nodes[i].x = x;
		nodes[i].y = y;
	}
	
	cin>>m;
	int from,to;
	for(int i = 1;i <= m;i++){
		cin>>from>>to;
		
		addEdge(from,to);
	}
	
//	//遍历看 
//	for(int i = 1; i <=n ;i++){
//		cout<<"节点"<<i<<":"<<endl;
//		for(int j = 0;j < graph[i].size();j ++){
//			cout<<"("<<graph[i][j].to<<" "<<g
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值