hdu 5521(dijkstra+缩点)
来源:互联网 发布:网络银行系统的组成 编辑:程序博客网 时间:2024/06/06 00:24
题意:题目大意:A,B两个人分别在1和n区。求碰面区间使得两人所花时间最短
分析: 因为是以集合给出,所以按集合中的边数两两建边会导致边数过多,所以一个集合添加一个缩点,到缩点的距离为当前集合的值
#include <cstdio>#include <cstring>#include <iostream>#include <queue>#include <algorithm>#include <vector>using namespace std;typedef long long int ll;typedef pair<int,int> P;typedef pair<long long int ,int > PI;#define INF 0x3f3f3f3f#define maxn 200050vector<P>E[maxn];ll dis[maxn];ll disc[maxn];int T;int n , m ;void dijkstra(int s, ll *d){ for(int i = 0 ; i < maxn ; ++i) d[i] = INF; d[s] = 0; priority_queue<PI ,vector<PI> , greater<PI> >Q; Q.push(PI(0,s)); while(!Q.empty()) { ll c = Q.top().first; int u = Q.top().second; Q.pop(); if( d[u] < c )continue; for(int i = 0 ; i < E[u].size() ; ++i) { int v = E[u][i].first; ll w = E[u][i].second; if( d[v] > d[u] + w ) { d[v] = d[u] + w; Q.push(PI(d[v],v)); } } }}int main(){ cin >> T; int cas = 0; while( T-- ) { for(int i = 0 ; i< maxn ; ++i)E[i].clear(); cin >> n >> m ; for(int i = 1 ; i <= m ; ++i) { int c , k ; scanf("%d %d",&c,&k); for(int j = 0 ; j < k ; ++j) { int b; scanf("%d",&b); E[i + n].push_back(P(b,c)); E[ b ].push_back(P(i+n,0)); } } dijkstra(1,dis); dijkstra(n,disc); ll ans = INF; for(int i = 1 ; i <= n ; ++i){ ans = min(ans,max(dis[i],disc[i])); } printf("Case #%d: ",++cas); if( ans == INF ) { printf("Evil John\n"); continue; } else printf("%lld\n",ans); priority_queue<int,vector<int>,greater<int> >Q; for(int i = 1 ; i <= n ; ++i){ if( disc[i] <= ans && dis[i] <= ans ){ Q.push(i); } } while( Q.size() > 1 ){ printf("%d ",Q.top()); Q.pop(); } printf("%d\n",Q.top());Q.pop(); }}
阅读全文
0 0
- hdu 5521(dijkstra+缩点)
- HDU 5521 Meeting ( nlogn的dijkstra+拆点)
- HDU-5521 Meeting(Dijkstra)
- [hdu 5521 Meeting] 拆边 + Dijkstra
- HDU 2066 一个人的旅行(Dijkstra求特殊点的单源最短路径)
- hdu 1546 Dijkstra变形
- hdu 2544 (dijkstra)
- hdu 2544 dijkstra
- HDU 2066 dijkstra
- hdu 2544 dijkstra
- HDU-3790(dijkstra())
- hdu 2112dijkstra
- HDU 3665 dijkstra floyd
- HDU 2544 dijkstra
- hdu 2066-dijkstra
- hdu 3873 dijkstra
- hdu 1874 Dijkstra算法
- HDU 2112 Map+Dijkstra
- 【Gradle Build Tool 4.1用户指南】Chapter 1. Introduction 第一章、介绍
- springMVC入门搭建
- HDFS相关JAVA API
- windows 互斥及临界区test-demo
- WinForm 带下划线的TextBox
- hdu 5521(dijkstra+缩点)
- chown和chmod的用法
- 如何利用机器学习预测房价?
- Date
- 习题 7.8 写一个函数,输入一个4位数字,要求输出这4个数字字符,但每两个数字间空一个空格。如输入1990,应输出“1 9 9 0”。
- 如何解决android studio的模拟器有密码的问题
- 基于Vue全家桶制作的的高仿美团APP
- 客户信用额度
- Unity3D 5.x资源加载介绍