本来用一个map判重边结果T了, 实际上可以直接给边上打标记即可

int n, m;
struct _ {int to,w,vis;};
vector<_> g[N];
int dis[N];
queue<int> q; void dfs(int x, int c, int d) {
dis[x] = d, q.push(x);
for (auto &e:g[x]) if (!e.vis&&e.w==c) {
e.vis = 1;
if (dis[e.to]>=d) dfs(e.to,c,d);
}
} void work() {
REP(i,1,m) {
int u, v, w;
scanf("%d%d%d", &u, &v, &w);
g[u].pb({v,w,0}),g[v].pb({u,w,0});
}
q.push(1);
dis[1]=0;
while (q.size()) {
int x = q.front(); q.pop();
for (auto &e:g[x]) if (!e.vis) {
e.vis = 1;
if (dis[e.to]>=dis[x]+1) dfs(e.to,e.w,dis[x]+1);
}
}
printf("%d\n", dis[n]==INF?-1:dis[n]);
} int main() {
for (; ~scanf("%d%d", &n, &m); ) {
REP(i,0,n) g[i].clear(),dis[i]=INF;
work();
}
}

hdu 6386 Age of Moyu (重边判断)的更多相关文章

  1. HDU 6386 Age of Moyu 【BFS + 优先队列优化】

    任意门:http://acm.hdu.edu.cn/showproblem.php?pid=6386 Age of Moyu Time Limit: 5000/2500 MS (Java/Others ...

  2. HDU 6386 Age of Moyu (最短路+set)

    <题目链接> 题目大意:给定一张无向图,有n个点m条边,从一条边到另一条边,如果两边的指不同 花费就要+1,如果相同就不需要花费. 先从1走到n问最小花费是多少.(第一条边的花费都是1) ...

  3. HDU - 6386 Age of Moyu 2018 Multi-University Training Contest 7 (Dijkstra变型)

    题意:N个点M条边的无向图,每条边都有属于自己的编号,如果一条路径上的边编号都相同,那么花费仅为1:改变至不同编号的路径,花费加1,无论这个编号之前是否走过. 分析:记录每个点的最小花费,再用set维 ...

  4. HDU 6386 Age of Moyu

    Problem Description Mr.Quin love fishes so much and Mr.Quin’s city has a nautical system,consisiting ...

  5. HDU - 6386 Age of Moyu (双端队列+bfs)

    题目链接 双端队列跑边,颜色相同的边之间的花费为0,放进队首:不同的花费为1,放进队尾. 用Dijkstra+常数优化也能过 #include<bits/stdc++.h> using n ...

  6. HDU 6395 分段矩阵快速幂 HDU 6386 建虚点+dij

    http://acm.hdu.edu.cn/showproblem.php?pid=6395 Sequence Time Limit: 4000/2000 MS (Java/Others)    Me ...

  7. HDU 4738 Caocao's Bridges(Tarjan求桥+重边判断)

    Caocao's Bridges Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  8. hdu6386 Age of Moyu【最短路】

    Age of Moyu Time Limit: 5000/2500 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) To ...

  9. Age of Moyu HDU - 6386 (杭电多校7A)

    给出n和点,m条边,每条边有各自的标号,进入第一个标号需要消耗1的费用,此后转换标号需要1费用,在同一个标号上走不需要费用.问你从1到n最少需要多少费用. 最短路变形,把第一个点看成不存在的标号,然后 ...

随机推荐

  1. 为linux扩展swap分区

    1.查看当前swap分区使用情况 [root@localhost ~]# swapon -s Filename Type Size Used Priority /dev/sda2            ...

  2. flight framework 核心解读

    http://blog.csdn.net/sky_zhe/article/details/38906689?utm_source=tuicool&utm_medium=referral

  3. python设置redis过期时间

    import time import redis if __name__ == "__main__": try: conn=redis.StrictRedis(host='192. ...

  4. curl 模拟GET\POST请求,以及curl post上传文件

    https://blog.csdn.net/fungleo/article/details/80703365

  5. [SharpMap] 屏幕坐标和Map坐标转换

    1. SharpMap中屏幕坐标和地图Map坐标转换: using System.Drawing; using GeoAPI.Geometries; namespace SharpMap.Utilit ...

  6. idea一个类中,各个修饰符的符号表示

    1: 2:

  7. loadrunner11的移动端性能测试之脚本优化

    测试步骤之脚本优化(Script) 看到这里,是不是疑惑录制好的脚本还需要优化吗,答案是肯定的. 优化概要 脚本优化包括插入注释(Comment),插入事务(Transaction),插入检查点(Ch ...

  8. PAT 1102 Invert a Binary Tree[比较简单]

    1102 Invert a Binary Tree(25 分) The following is from Max Howell @twitter: Google: 90% of our engine ...

  9. 解决FlexPaper分页分段加载问题(转)

    FlexPaper是一个开源的PDF文档在线查看控件.用户查看PDF文档不需要安装Acrobat Reader,但需要利用像SwfTools这样的工具预先将PDF文档转成SWF格式的文件.FlexPa ...

  10. 4.12 Routing -- Preventing And Retrying Transitions

    一.概述 在一个路由的跳转过程中,Ember路由器传递一个跳转对象到被跳转调用的路由的不同的hooks中.任何一个hook获取这个跳转对象,有能力通过调用transition.abort()终止跳转, ...