题意:给力一张无向图,有一些边是正常道路,有一些边是铁路,问最多能删除几条铁路使得所有点到首都(编号为1)的最短路长度不变。

思路:求不能删除的铁路数,总数减掉就是答案。先求出首都到所有点的最短路,求完最短路后,枚举除首都外所有点,如果这个点被更新的边中只有铁路,那么就有一条铁路不能删除。

注意:这里求最短路一开始用SPFA在第45个点TLE,最后换成带堆优化Dijkstra

#include<cstring>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include <iostream>
#include<queue>
#define M 1000010
#define N 100050
#define LL __int64
#define INF (1000000000000000LL)
using namespace std;
struct node {
int to, nx, va, flag;
} e[M];
int head[N], ecnt;
struct info {
int id, va;
};
bool operator<(info a, info b) {
return a.va > b.va;
}
priority_queue<info> q;
void addedge(int x, int y, int va, int flag) {
e[ecnt].to = y;
e[ecnt].va = va;
e[ecnt].nx = head[x];
e[ecnt].flag = flag;
head[x] = ecnt++;
}
bool bo[N];
LL d[N];
int n, m, k;
void Dij() {
for (int i = ; i <= n; ++i)
d[i] = INF;
memset(bo, , sizeof(bo));
d[] = ;
int st = , ed = ;
while (!q.empty())
q.pop();
info a;
a.va = ;
a.id = ;
q.push(a);
while (!q.empty()) {
a = q.top();
q.pop();
int now = a.id;
if (bo[now])
continue;
bo[now] = true;
for (int j = head[now]; j != -; j = e[j].nx) {
int u = e[j].to;
if (d[u] > d[now] + e[j].va) {
d[u] = d[now] + e[j].va;
a.id=u;
a.va=d[u];
q.push(a);
}
}
}
}
void init() {
scanf("%d%d%d", &n, &m, &k);
memset(head, -, sizeof(head));
ecnt = ;
for (int i = ; i < m; ++i) {
int x, y, z;
scanf("%d%d%d", &x, &y, &z);
addedge(x, y, z, );
addedge(y, x, z, );
}
for (int i = ; i < k; ++i) {
int x, y;
scanf("%d%d", &x, &y);
addedge(, x, y, );
addedge(x, , y, );
}
}
void solve() {
Dij();
int ans = k;
for (int i = ; i <= n; ++i) {
int flag = , flag1 = ;
for (int j = head[i]; j != -; j = e[j].nx) {
int u = e[j].to;
if (d[u] + e[j].va == d[i]) {
if (e[j].flag == )
flag = ;
else
flag1 = ;
}
}
if (flag == && flag1 == )
ans--;
}
printf("%d\n", ans);
}
int main() {
init();
solve(); }

Codeforces Round #257 (Div. 1) (Codeforces 449B)的更多相关文章

  1. Codeforces Round #257 (Div. 1) (Codeforces 449D)

    思路:定义f(x)为 Ai & x==x  的个数,g(x)为x表示为二进制时1的个数,最后答案为    .为什么会等于这个呢:运用容斥的思想,如果 我们假设 ai&x==x 有f(x ...

  2. Codeforces Round #257 (Div. 1)A~C(DIV.2-C~E)题解

    今天老师(orz sansirowaltz)让我们做了很久之前的一场Codeforces Round #257 (Div. 1),这里给出A~C的题解,对应DIV2的C~E. A.Jzzhu and ...

  3. Codeforces Round #524 (Div. 2) codeforces 1080A~1080F

    目录 codeforces1080A codeforces 1080B codeforces 1080C codeforces 1080D codeforces 1080E codeforces 10 ...

  4. Codeforces Round #257 (Div. 1) C. Jzzhu and Apples (素数筛)

    题目链接:http://codeforces.com/problemset/problem/449/C 给你n个数,从1到n.然后从这些数中挑选出不互质的数对最多有多少对. 先是素数筛,显然2的倍数的 ...

  5. Codeforces Round #257 (Div. 2) B. Jzzhu and Sequences (矩阵快速幂)

    题目链接:http://codeforces.com/problemset/problem/450/B 题意很好懂,矩阵快速幂模版题. /* | 1, -1 | | fn | | 1, 0 | | f ...

  6. Codeforces Round #257 (Div. 1)449A - Jzzhu and Chocolate(贪婪、数学)

    主题链接:http://codeforces.com/problemset/problem/449/A ------------------------------------------------ ...

  7. Codeforces Round #257 (Div. 2) A. Jzzhu and Children(简单题)

    题目链接:http://codeforces.com/problemset/problem/450/A ------------------------------------------------ ...

  8. Codeforces Round #257(Div. 2) B. Jzzhu and Sequences(矩阵高速幂)

    题目链接:http://codeforces.com/problemset/problem/450/B B. Jzzhu and Sequences time limit per test 1 sec ...

  9. Codeforces Round #257 (Div. 2)

    A - Jzzhu and Children 找到最大的ceil(ai/m)即可 #include <iostream> #include <cmath> using name ...

随机推荐

  1. [转载] 深入 nginx 架构

    原文: http://www.cnbeta.com/articles/402709.htm 了解 nginx 架构帮助我们学习如何开发高性能 web 服务. 为了更好地理解设计,你需要了解NGINX是 ...

  2. mysql 事件调度器

    1.mysql事件调度器,也就是计划任务,计划做某事,有两种方式: 2.在某个时间点做某事,AT TIMESTAMP [+ INTERVAL INTERVAL] 某个时间点加上偏移. 3.定时地做某事 ...

  3. Java中的Double类型计算

    一.问题的提出: 如果我们编译运行下面这个程序会看到什么?public class Test{    public static void main(String args[]){        Sy ...

  4. RAC 移动 OCR

    1.查看是否有OCR备份 # ocrconfig -showbackup 如果没有就备份一份 # ocrconfig -export /oracle/bak/ocr/ocr_11291433_exp. ...

  5. 【MRPT】【icp-slam-live】Vs2013+ cmake3.6.1 + mrpt1.4.0+opencv2.9.4+wxWidget3.0.2环境配置

    Win10下Vs2013 + cmake3.6.1 + mrpt1.4.0+opencv2.9.4+wxWidget3.1.0环境配置 所接触过的最令我崩溃的环境配置.之前没有考虑到vs2013 20 ...

  6. eclipse 新建 maven 项目 步骤(初级入门新手)

    安装 maven(百度) 和在eclipse 中svn(上一篇) 修改 maven 本地仓库 eclipse 属性 maven--> installations-->添加新的 自定义安装的 ...

  7. 响应式web设计读书笔记

    1.媒体查询可以在链接link标签和具体的CSS中使用: 2.通过<link>标签的 media 属性为样式表指定设备类型和其他条件  中间用and和()来分隔,如下 <link r ...

  8. 写在学习Java GUI之前

    Java GUI就是用Java语言开发桌面应用,而Java又有三个Java GUI库,分别为AWT,Swing和SWT/JFace. 现在要学的是Swing库. 后记:开发桌面应用,不止一种技术,现在 ...

  9. php向数据库写数据逻辑

    先写php 文件 1.post请求 1)先确定传进来的数据有值 没有就退出程序 if(!isset($_POST['username'])){ die('没有传值') } 2)设config.php ...

  10. SPSS中变量的度量标准

    在SPSS中,每一个变量都有一个度量标准,这些度量标准说明变量的含义和属性,会对后续的分析产生影响. 1.名义:名义表示定类变量,定类变量表示事物的类别,只能计算频数和频率,各类别之间没有大小.顺序. ...