博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
BZOJ 1073: [SCOI2007]kshort
阅读量:4931 次
发布时间:2019-06-11

本文共 2490 字,大约阅读时间需要 8 分钟。

二次联通门 : 

 

 

 

 

/*    BZOJ 1073: [SCOI2007]kshort               A* k短路      但是会爆一个点, 是卡A*的*/#include 
#include
#include
#include
#include
#include
#include
const int BUF = 12313123;char Buf[BUF], *buf = Buf;#define Max 120#define Vec std :: vectorint dis[Max], N, M, S, T, K;struct D{ Vec
r; bool is[Max]; int u, d; bool operator < (const D A) const { return this->d + dis[this->u] > A.d + dis[A.u]; }};bool visit[Max];struct E { E *n; int v, d; };E *Z_list[Max], *F_list[Max], poor[(Max * Max) << 1], *Ta = poor;inline int read (int &now){ for (now = 0; !isdigit (*buf); ++ buf); for (; isdigit (*buf); now = now * 10 + *buf - '0', ++ buf);}void Spfa (){ std :: queue
Q; memset (dis, 0x3f, sizeof dis); int n; E *e; for (Q.push (T), dis[T] = 0, visit[T] = true; !Q.empty (); Q.pop ()) { n = Q.front (); visit[n] = false; for (e = F_list[n]; e; e = e->n) if (dis[e->v] > dis[n] + e->d) { dis[e->v] = dis[n] + e->d; if (!visit[e->v]) visit[e->v] = true, Q.push (e->v); } }} Vec
Answer; int C;inline int min (int a, int b) { return a < b ? a : b; }bool Comp (D A, D B){ if (A.d != B.d) return A.d < B.d; int L = min (A.r.size (), B.r.size ()); for (register int i = 0; i < L; ++ i) if (A.r[i] != B.r[i]) return A.r[i] < B.r[i]; return A.r.size () < B.r.size ();}void A_star (){ std :: priority_queue
H; D n, res; n.u = S, n.d = 0; n.r.push_back (S); E *e; n.is[S] = true; H.push (n); for (; !H.empty (); ) { n = H.top (); H.pop (); if (n.u == T) { if ((++ C) > K && n.d > Answer[K - 1].d) break; Answer.push_back (n); } for (e = Z_list[n.u]; e; e = e->n) if (!n.is[e->v]) { res = n; res.u = e->v; res.r.push_back (e->v); res.d = e->d + n.d, res.is[e->v] = true, H.push (res); } } if (Answer.size () < K) { printf ("No\n"); exit (0); } std :: sort (Answer.begin (), Answer.end (), Comp);}int Main (){ fread (buf, 1, BUF, stdin); read (N), read (M), read (K); read (S), read (T); register int i; int x, y, z, Size; for (i = 1; i <= M; ++ i) { read (x), read (y), read (z); ++ Ta, Ta->v = y, Ta->d = z, Ta->n = Z_list[x], Z_list[x] = Ta; ++ Ta, Ta->v = x, Ta->d = z, Ta->n = F_list[y], F_list[y] = Ta; } for (Spfa (), A_star (), i = 0, Size = Answer[K - 1].r.size () - 1; i < Size; ++ i) printf ("%d-", Answer[K - 1].r[i]); printf ("%d", Answer[K - 1].r[i]); return 0;}int ZlycerQan = Main (); int main (int argc, char *argv[]) {;}

 

转载于:https://www.cnblogs.com/ZlycerQan/p/7491176.html

你可能感兴趣的文章
数据挖掘-同比与环比
查看>>
nginx+php详解
查看>>
怎样取php一个字符串中的某个字符
查看>>
我的友情链接
查看>>
RedHat6 管理应用服务【11】
查看>>
stm32F10x复习-1
查看>>
redis的学习使用(ubuntu系统下)
查看>>
20135226黄坤信息安全系统设计基础期末总结
查看>>
轻松快捷创建VSFTP虚拟用户
查看>>
[转]Javascript原型继承
查看>>
[转] vue异步处理错误
查看>>
CSS 3D动画概述菜鸟级解读之一
查看>>
分布式系列文章 —— 从 ACID 到 CAP / BASE
查看>>
方法签名与方法重载
查看>>
cmake 变量
查看>>
[Programming Entity Framework] 第2章 探究实体数据模型(EDM)(一)
查看>>
shell环境
查看>>
Java调用C++类库--JNI
查看>>
gles和opengl版本对照表
查看>>
微信开发(二)自己的代码
查看>>