bzoj4400
/*
* 此题同bzoj2725
* 增加了枚举边的操作
*/
#include <bits/stdc++.h> const int N = 2e5 + ;// oo = 999999999; #define LL long long const LL oo = 9e18; int n, m, S, T;
int Short_path[N], Snum[N], Tnum[N], Id[N], path_js;
bool vis[N];
int head[N], now;
struct Node {int u, v, w, nxt;} G[N << ];
LL dis_s[N], dis_t[N];
LL Minn[N << ], Ans[N]; inline void Add(int u, int v, int w) {
G[++ now].v = v, G[now].w = w, G[now].nxt = head[u], head[u] = now;
} struct Node_ {
int u; LL dis;
bool operator < (const Node_ a) const {return dis > a.dis;}
}; std:: priority_queue <Node_> Q; void Dijkstra(int start, LL dis_[]) {
for(int i = ; i <= n; i ++) dis_[i] = oo, vis[i] = ;
Node_ now; now = (Node_) {start, }; dis_[start] = ;
Q.push(now);
while(!Q.empty()) {
Node_ topp = Q.top();
Q.pop();
if(vis[topp.u]) continue;
vis[topp.u] = ;
for(int i = head[topp.u]; ~ i; i = G[i].nxt) {
int v = G[i].v;
if(dis_[v] > dis_[topp.u] + G[i].w) {
dis_[v] = dis_[topp.u] + G[i].w;
Q.push((Node_) {v, dis_[v]});
}
}
}
} inline void Bfs(int x, LL dis_[], int bel[]) {
std:: queue <int> Q1;
Q1.push(Short_path[x]);
bel[Short_path[x]] = x;
while(!Q1.empty()) {
int topp = Q1.front();
Q1.pop();
for(int i = head[topp]; ~ i; i = G[i].nxt) {
int v = G[i].v;
if(!Id[v] && !bel[v] && dis_[v] == dis_[topp] + G[i].w) {
bel[v] = x;
Q1.push(v);
}
}
}
} #define lson jd << 1
#define rson jd << 1 | 1 void Sec_G(int l ,int r, int jd, int x, int y, LL num) {
if(x <= l && r <= y) {
Minn[jd] = std:: min(Minn[jd], (LL)num);
return ;
}
int mid = (l + r) >> ;
if(x <= mid) Sec_G(l, mid, lson, x, y, num);
if(y > mid) Sec_G(mid + , r, rson, x, y, num);
} void Dfs_tree(int l, int r, int jd) {
if(l == r) {
Ans[l] = Minn[jd];
return ;
}
int mid = (l + r) >> ;
Minn[lson] = std:: min(Minn[lson], Minn[jd]);
Minn[rson] = std:: min(Minn[rson], Minn[jd]);
Dfs_tree(l, mid, lson), Dfs_tree(mid + , r, rson);
} #define gc getchar() inline LL read() {
LL x = ; char c = gc;
while(c < '' || c > '') c = gc;
while(c >= '' && c <= '') x = x * + c - '', c = gc;
return x;
} bool visit[N << ]; int main() {
n = read(), m = read();
for(int i = ; i <= (N << ); i ++) Minn[i] = oo;
for(int i = ; i <= n; i ++) head[i] = -;
for(int i = ; i <= m; i ++) {
int u = read(), v = read(), w = read();
Add(u, v, w), Add(v, u, w);
}
S = , T = n;
Dijkstra(S, dis_s);
Dijkstra(T, dis_t);
for(int i = S; i != T; i = i) {
// visit[i] = 1;
Short_path[++ path_js] = i;
Id[i] = path_js;
for(int j = head[i]; ~ j; j = G[j].nxt) {
if(dis_t[i] == G[j].w + dis_t[G[j].v]) {
i = G[j].v;
visit[j] = ;
break;
}
}
}
Short_path[path_js + ] = T, Id[T] = path_js + ;
for(int i = ; i <= path_js; i ++) Bfs(i, dis_s, Snum);
for(int i = path_js + ; i >= ; i --) Bfs(i, dis_t, Tnum);
for(int i = ; i <= n; i ++) {
for(int j = head[i]; ~ j; j = G[j].nxt) {
int v = G[j].v;
if(visit[j]) continue;
if(Snum[i] < Tnum[v] && Snum[i] && Tnum[v]) {
Sec_G(, path_js, , Snum[i], Tnum[v] - , dis_s[i] + G[j].w + dis_t[v]);
}
}
}
Dfs_tree(, path_js, );
LL Dis = , js;
for(int i = ; i <= path_js; i ++) {
if(Ans[i] > Dis && Ans[i] != oo) Dis = Ans[i], js = ;
else if(Ans[i] == Dis) js ++;
}
if(Dis == dis_s[T]) js += m - path_js;
std:: cout << Dis << " " << js;
return ;
}
?
bzoj4400的更多相关文章
- bzoj4400: tjoi2012 桥
先传代码再填坑 #include <iostream> #include <cstdio> #include <cmath> #include <cstrin ...
- BZOJ4400 TJOI2012桥(最短路+线段树)
首先找出任意一条1-n的最短路径.显然删除的边只有在该最短路上才会对最短路长度产生影响. 不会证明地给出一个找不到反例的结论:删除一条边后,新图中一定有一条1-n的最短路径上存在一条边x->y, ...
随机推荐
- [ZJOI2007]捉迷藏 (线段树,括号序列)
大意: 给定树, 要求维护一个点集, 支持删点添点, 询问点集直径. 本题做法比较多. 一个显然的做法是, 线段树维护区间直径, 然后根据点集直径的性质, 合并后直径端点一定是四个端点其中两个, 枚举 ...
- C#一些面试知识题
1.简述 private. protected. public.internal 修饰符的访问权限答:private:私有成员, 在类的内部才可以访问(只能从其声明上下文中进行访问). protect ...
- Map集合中key不存在时使用toString()方法、valueOf()方法和强制转换((String))之间的区别
1.toString()方法 底层代码 public String toString() { return this; } 其返回值为String类型的字符串本身 Map<String, Obj ...
- Python内置函数系列
Python内置(built-in)函数随着python解释器的运行而创建.在Python的程序中,你可以随时调用这些函数,不需要定义. 作用域相关(2) locals() :以字典类型返回当前位置 ...
- 装机篇:ubuntu 14.04 在英文环境下安装中文输入法(转载)
ubuntu默认的输入法是ibus,综合网上评论,fcitx的支持者更多,而且个人感觉fcitx也的确不错,可以满足日常输入. STEP1: 在Ubuntu Software Center 搜索fci ...
- spider _其他库的简单操作与方法
PHP : 网络IO java : 代码笨重,代码量很大 C/C++ :虽然效率高,但是代码成型很慢 1 通用网络爬虫(搜索引擎引用,需要遵守robots协议) 1 搜索引擎如何获取一个新网站的 UR ...
- 配置由Spring处理json乱码
<mvc:annotation-driven> <mvc:message-converters register-defaults="true"> < ...
- 用python实现新词发现程序——基于凝固度和自由度
互联网时代,信息产生的数量和传递的速度非常快,语言文字也不断变化更新,新词层出不穷.一个好的新词发现程序对做NLP(自然预言处理)来说是非常重要的. N-Gram加词频 最原始的新词算法莫过于n-gr ...
- 线程的 run()和 start()有什么区别?(未完成)
线程的 run()和 start()有什么区别?(未完成)
- 14、RALM: 实时 look-alike 算法在推荐系统中的应用
转载:https://zhuanlan.zhihu.com/p/71951411 RALM: 实时 look-alike 算法在推荐系统中的应用 0. 导语 本论文题为<Real-time At ...