Ideal Path(UVA-1599)

题目

推荐
题意
给定一个n个顶点,m条边的无向图,每条边有颜色值(长度均为1),求出起点到终点的最短路径(颜色值表示),若存在多解,则输出路径中颜色值字典序最小者。(注意重边,自环)
思路
逆向BFS求最短路径,正向BFS求字典序最小
代码如下

#include<bits/stdc++.h>
using namespace std;
const int maxn=1e6+5;
const int inf=0x3f3f3f3f;
const double eps=1e-8;
typedef long long ll;
typedef pair<int,int> PII;
int n,m;
struct Edge
{
   
   
    int from,to,color;
};

vector<Edge>edges;
vector<int>G[maxn];
void init()
{
   
   
    for(int i=0;i<=n;i++)
        G[i].clear();
    edges.clear();
}

void add(int from,int to,int color)
{
   
   
    edges.push_back({
   
   from,to,color});
    int m=edges.size();
    G[from
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值