标签:ora desc not print case http des cost scribe
Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 6865 Accepted Submission(s): 2085
1 /************************************************************************* 2 > File Name: meeting.cpp 3 > Author: CruelKing 4 > Mail: 2016586625@qq.com 5 > Created Time: 2019年09月21日 星期六 11时26分48秒 6 本题思路:用Dijkstra结果wa了,很无奈,换了spfa就过了,哦,不是就过了,是 7 各种TLE,WA,PE都不提示,给别人提示的是WA,时段不同也能T.搞心态的题...... 8 就是个傻逼题:稍加分析就知道一个块内全部建边是不可行的,对每个块建立一个超级 9 源点,块内的点向超级源点连一条边,跑一波最短路,后续细节处理很简单.傻逼题. 10 ************************************************************************/ 11 12 #include <cstdio> 13 #include <cstring> 14 #include <queue> 15 #include <algorithm> 16 #include <climits> 17 using namespace std; 18 19 const int maxn = 2000000 + 5, maxm = 1000000 + 5; 20 21 typedef long long ll; 22 23 ll inf = LLONG_MAX; 24 25 struct Edge { 26 int to, cost, next; 27 } edge[maxm << 1]; 28 29 int head[maxn], tot; 30 31 int n, m; 32 33 ll diss[maxn], dist[maxn]; 34 35 ll dis[maxn]; 36 37 bool vis[maxn]; 38 39 void init() { 40 memset(head, -1,sizeof head); 41 tot = 0; 42 } 43 44 void addedge(int u, int v, int w) { 45 edge[tot].to = v; edge[tot].cost = w; edge[tot].next = head[u]; head[u] = tot ++; 46 edge[tot].to = u; edge[tot].cost = w; edge[tot].next = head[v]; head[v] = tot ++; 47 } 48 49 void dijkstra(int s, ll (&_dis)[maxn]) { 50 memset(vis, false, sizeof vis); 51 for(int i = 1; i <= m + n; i ++) _dis[i] = inf; 52 _dis[s] = 0; 53 vis[s] = true; 54 queue <ll> que; 55 que.push(s); 56 while(!que.empty()) { 57 int u = que.front(); que.pop(); vis[u] = false; 58 for(int i = head[u]; ~i; i = edge[i].next) { 59 int v = edge[i].to; 60 if(_dis[v] > _dis[u] + edge[i].cost) { 61 _dis[v] = _dis[u] + edge[i].cost; 62 if(!vis[v]) { 63 vis[v] = true; 64 que.push(v); 65 } 66 } 67 } 68 } 69 } 70 71 int ans[maxn], cnt; 72 73 int main() { 74 int t, v, w, num, _case = 0; 75 scanf("%d", &t); 76 while(t --) { 77 cnt = 0; 78 init(); 79 // memset(dis, inf ,sizeof dis); 80 scanf("%d %d", &n, &m); 81 for(int i = 1; i <= n + m; i ++) dis[i] = inf; 82 for(int u = 1; u <= m; u ++) { 83 scanf("%d %d", &w, &num); 84 while(num --) { 85 scanf("%d", &v); 86 addedge(u, m + v, w); 87 } 88 } 89 dijkstra(1 + m, diss); 90 dijkstra(n + m, dist); 91 ll Min = inf; 92 for(int i = 1 + m; i <= n + m; i ++) { 93 if(diss[i] < inf && dist[i] < inf) { 94 dis[i] = max(diss[i], dist[i]); 95 if(dis[i] < Min) Min = dis[i]; 96 } 97 } 98 printf("Case #%d: ", ++ _case); 99 if(Min != inf) { 100 printf("%lld\n", Min / 2); 101 for(int i = 1 + m; i <= n + m; i ++) { 102 if(dis[i] == Min) { 103 ans[cnt ++] = i - m; 104 } 105 } 106 for(int i = 0; i < cnt; i ++) { 107 if(i) printf(" "); 108 printf("%d", ans[i]); 109 } 110 printf("\n"); 111 } else printf("Evil John\n"); 112 } 113 return 0; 114 }
标签:ora desc not print case http des cost scribe
原文地址:https://www.cnblogs.com/bianjunting/p/11562832.html