HDU5876 Sparse Graph(2016亚洲区大连站网络赛)
来源:互联网 发布:mac有必要装office吗 编辑:程序博客网 时间:2024/05/15 23:17
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=5876
求补图的最短路,赛场上看到补图不知一时忘怎么回事了,因为数组开小了,RE一发。
#include <cstdio>#include <cstring>#include <algorithm>#include <stack>#include <string>#include <queue>#include <set>#include <list>#include <iostream>#include <cmath>#include <stack>#include <queue>#include <string>using namespace std;int T,p,q,n,m,k,t,r,y,x;int bb[1000003],cc[1000004],dd[1000003];struct node{ int u; int v;} aa[1000002];void ad(int v, int u){ aa[x].u = u; aa[x].v = bb[v]; bb[v] = x++; aa[x].u = v; aa[x].v = bb[u]; bb[u] = x++;}void bfs(int a){ set<int> pp; set<int >qq; for(int i = 1; i <= n; i++) if(i != a) pp.insert(i); queue<int>q1; q1.push(a); cc[a]=0; while(!q1.empty()) { int v =q1.front(); q1.pop(); for(int i= bb[v]; i!=-1; i=aa[i].v) { if(pp.find(aa[i].u) == pp.end()) continue; pp.erase(aa[i].u); qq.insert(aa[i].u); } set<int>::iterator p = pp.begin(); for(; p!=pp.end(); p++) cc[*p]=cc[v]+1,q1.push(*p); pp.swap(qq); qq.clear(); }}int main(){ scanf("%d", &T); while(T--) { memset(bb,-1,sizeof bb); memset(cc,-1,sizeof cc); x=0; scanf("%d%d", &n, &m); for(int i = 1; i <= m; i++) { scanf("%d%d", &p,&q); ad(p,q); } scanf("%d", &r); bfs(r); k=0; for(int i = 1; i <= n; i++) if(cc[i] != 0) { if(k==0) { printf("%d", cc[i]); k=1; } else printf(" %d", cc[i]); } printf("\n"); } return 0;}
0 0
- HDU5876 Sparse Graph(2016亚洲区大连站网络赛)
- 2016大连网络赛Sparse Graph
- 2016 ICPC 大连网络赛 HDU 5876 Sparse Graph
- hdu 5876 - Sparse Graph(2016大连网络赛) bfs
- 【icpc网络赛大连赛区】Sparse Graph
- HDU 5876 大连网络赛 Sparse Graph
- HDU 5876 Sparse Graph 大连网络赛
- hdu5876 Sparse Graph
- HDU5876-Sparse Graph
- hdu5876 补图求最短路 2016ACM ICPC 大连网络赛
- 补图上的BFS大连网络赛Sparse Graph
- hdu5876 Sparse Graph(补图最短路)
- hdu5876 Sparse Graph bfs + set
- hdu5876 Sparse Graph(补图上求最短路)
- 【2016-大连赛区网络赛-I】补图最短路(Sparse Graph,hdu 5876)
- [2016ICPC 大连网络预选赛] HDU5876 图论
- Sparse Graph(2016大连网赛)(hdu5876)(BFS+数据结构)
- hdu5876 Sparse Graph(补图+最短路)
- web安全 基于http连接的登录请求威胁
- sqlServer笔记
- Spring boot读取配置文件
- 数据库并发操作与数据的不一致性
- java关键字的适用总结
- HDU5876 Sparse Graph(2016亚洲区大连站网络赛)
- 再次研究几个动态库方面的编程
- iOS取绝对值的函数
- java垃圾回收机制
- Fragment的生命周期
- MySQL This function has none of DETERMINISTIC, NO SQL...错误1418 的原因分析及解决方法
- SIP和RTP
- UILabel修改行间距
- thinkphp利用phpexcel导入到Excel表格中