Codeforces Round #257 (Div. 1) (Codeforces 449B)
题意:给力一张无向图,有一些边是正常道路,有一些边是铁路,问最多能删除几条铁路使得所有点到首都(编号为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)的更多相关文章
- Codeforces Round #257 (Div. 1) (Codeforces 449D)
思路:定义f(x)为 Ai & x==x 的个数,g(x)为x表示为二进制时1的个数,最后答案为 .为什么会等于这个呢:运用容斥的思想,如果 我们假设 ai&x==x 有f(x ...
- 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 ...
- Codeforces Round #524 (Div. 2) codeforces 1080A~1080F
目录 codeforces1080A codeforces 1080B codeforces 1080C codeforces 1080D codeforces 1080E codeforces 10 ...
- Codeforces Round #257 (Div. 1) C. Jzzhu and Apples (素数筛)
题目链接:http://codeforces.com/problemset/problem/449/C 给你n个数,从1到n.然后从这些数中挑选出不互质的数对最多有多少对. 先是素数筛,显然2的倍数的 ...
- Codeforces Round #257 (Div. 2) B. Jzzhu and Sequences (矩阵快速幂)
题目链接:http://codeforces.com/problemset/problem/450/B 题意很好懂,矩阵快速幂模版题. /* | 1, -1 | | fn | | 1, 0 | | f ...
- Codeforces Round #257 (Div. 1)449A - Jzzhu and Chocolate(贪婪、数学)
主题链接:http://codeforces.com/problemset/problem/449/A ------------------------------------------------ ...
- Codeforces Round #257 (Div. 2) A. Jzzhu and Children(简单题)
题目链接:http://codeforces.com/problemset/problem/450/A ------------------------------------------------ ...
- 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 ...
- Codeforces Round #257 (Div. 2)
A - Jzzhu and Children 找到最大的ceil(ai/m)即可 #include <iostream> #include <cmath> using name ...
随机推荐
- 初试Celery
从@到celery 一.文档: 官网:http://www.celeryproject.org/ Celery3.1 ------------2016-7-19 18:26:55-- source:[ ...
- poj1971Parallelogram Counting
链接 越来越感觉到了数学的重要性!.. 这题本来用以斜率和长度为key值进行hash不过感觉很麻烦还TLE了.. 最后知道中点一样的话就可以组成平行四边形,初中数学就可以了.. #include &l ...
- access denied ("java.net.SocketPermission" "localhost:1527" "listen,resolve")
在开启derby服务出现该错误(测试hibernate 连接数据库时 使用myeclipse2014自带的数据库--windows->show view->other->Myecl ...
- Java中值传递的实质,形式参数与实际参数。引用传递。
值传递 package ch5; /** * Created by Jiqing on 2016/11/9. */ public class Transfer { public static void ...
- 进程 & 线程相关知识
不管Java,C++都有进程.线程相关的内容.在这里统一整理吧. Python的线程,其实是伪线程,不能真正的并发.下面也有讲. 线程自己基本上不拥有系统资源,只拥有一点在运行中必不可少的资源(如程序 ...
- 阿里云+wordpress搭建个人博客网站
[正文] 在阿里云上搭建使用个人博客主要分为以下几个步骤: 1.购买阿里云ECS主机 2.购买域名 3.申请备案 4.环境配置 5.安装wordpress 6.域名解析 声明一下,本人对服务器端的知识 ...
- 20160805_Win7x64刻录CentOS6.4x64启动光盘
使用的软件为:UltraISO.v.9.6.2.3059.exe Win7 x64 刻录 CentOS6.4 x64 启动盘,有提示错误信息. 网上查了一下,是 AHCI 的驱动没有安装.来到 联想t ...
- PHP与Ajax的交互更新页面
PHP与Ajax的交互更新页面 本次主要学习ajax的概念以及怎么与PHP之间进行交互操作 1.什么是Ajax? 国内翻译常为“阿贾克斯”和阿贾克斯足球队同音,AJAX 是一种用于创建快速动态网 ...
- qq 换密保方法 只要有密保就好换手机
特别提醒:必须先绑定手机再做其它操作!!否则有几率冻结更换密保手机号后审核时间2-12小时,请您确定审核通过后再使用(本链接所有号码不需要挂七天常用IP即可绑定手机后改密)电脑换绑定手机方法:复制账号 ...
- JBPM工作流入门总结
关于JBPM工作流 1.工作流 工作流是一项分离业务操作和系统流程的技术.工作流由实体(Entity).参与者(Participant).流程定义(Flow Definition).工作流引擎(Eng ...