luogu 1144
最短路计数
#include <bits/stdc++.h> using namespace std;
const int N = 1e6 + , M = 2e6 + ;
const int oo = ( << ); #define gc getchar() inline int read() {
int x = ; char c = gc;
while(c < '' || c > '') c = gc;
while(c >= '' && c <= '') x = x * + c - '', c = gc;
return x;
} struct Node {
int u, dis_;
bool operator < (Node a) const {
return dis_ > a.dis_;
}
};
struct Node_2 {int u, v, w, nxt;} G[M];
int head[N], dis[N], cnt;
int f[N];
int n, m, k, Mod;
bool vis[N];
priority_queue <Node> Q;
int Cnt[N]; inline void Link(int u, int v, int w) {
G[++ cnt].u = u; G[cnt].v = v; G[cnt].w = w; G[cnt].nxt = head[u]; head[u] = cnt;
} void Dij(int start) {
for(int i = ; i <= n; i ++) dis[i] = oo, vis[i] = , Cnt[i] = ;
Q.push((Node) {start, });
dis[start] = ;
Cnt[start] = ;
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) {
Cnt[v] = Cnt[topp.u];
dis[v] = dis[topp.u] + G[i].w;
Q.push((Node) {v, dis[v]});
} else if(dis[v] == dis[topp.u] + G[i].w) {
(Cnt[v] += Cnt[topp.u]) %= Mod;
}
}
}
} int main() {
Mod = ;
n = read(), m = read();
for(int i = ; i <= n; i ++) head[i] = -;
cnt = ;
for(int i = ; i <= m; i ++) {
int u, v, w;
u = read(), v = read(), w = ;
Link(u, v, w); Link(v, u, w);
}
Dij();
for(int i = ; i <= n; i ++) {
cout << Cnt[i] % Mod << "\n";
}
return ;
}
luogu 1144的更多相关文章
- POJ 1144
http://poj.org/problem?id=1144 题意:给你一些点,某些点直接有边,并且是无向边,求有多少个点是割点 割点:就是在图中,去掉一个点,无向图会构成多个子图,这就是割点 Tar ...
- Luogu 魔法学院杯-第二弹(萌新的第一法blog)
虽然有点久远 还是放一下吧. 传送门:https://www.luogu.org/contest/show?tid=754 第一题 沉迷游戏,伤感情 #include <queue> ...
- luogu p1268 树的重量——构造,真正考验编程能力
题目链接:http://www.luogu.org/problem/show?pid=1268#sub -------- 这道题费了我不少心思= =其实思路和标称毫无差别,但是由于不习惯ACM风格的题 ...
- ural 1144. The Emperor's Riddle
1144. The Emperor's Riddle Time limit: 1.0 secondMemory limit: 4 MB Background In the olden times th ...
- poj 1144 Network 图的割顶判断模板
Network Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 8797 Accepted: 4116 Descripti ...
- POJ 1144 Network(Tarjan求割点)
Network Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12707 Accepted: 5835 Descript ...
- poj 1144 Network(无向图求割顶数)
题目链接:poj 1144 题意就是说有 n(标号为 1 ~ n)个网点连接成的一个网络,critical places 表示删去后使得图不连通的顶点,也就是割顶,求图中割顶的个数. 直接上大白书上的 ...
- [luogu P2170] 选学霸(并查集+dp)
题目传送门:https://www.luogu.org/problem/show?pid=2170 题目描述 老师想从N名学生中选M人当学霸,但有K对人实力相当,如果实力相当的人中,一部分被选上,另一 ...
- [luogu P2647] 最大收益(贪心+dp)
题目传送门:https://www.luogu.org/problem/show?pid=2647 题目描述 现在你面前有n个物品,编号分别为1,2,3,--,n.你可以在这当中任意选择任意多个物品. ...
随机推荐
- DEFAULT CURRENT_TIMESTAMP
alter table t_user_channel_info change update_dttm update_dttm timestamp NOT NULL DEFAULT CURRENT_TI ...
- 题解-APIO2019桥梁
problem \(\mathrm {loj-3145}\) 题意概要:给定一张 \(n\) 点 \(m\) 边的无向图,边有边权,共 \(q\) 次操作,每次会将第 \(x\) 条边的权值改为 \( ...
- C# List 转 Tree 公共方法
# 用C# 写了个List数据结构转树形数据结构的公共扩展方法 /// <summary> /// 将列表转换为树形结构 /// </summary> /// <type ...
- 免root xshell连接termux
免root实现xshell连接termux termux为安卓手机上的一款模拟linux终端的应用,由于手机上打字比较麻烦,所以想到了用电脑上的xshell通过ssh连接termux,以实现电脑控制t ...
- 六、eureka客户端自动注册服务
所有文章 https://www.cnblogs.com/lay2017/p/11908715.html 正文 上一篇文章,我们稍微了解了一下eureka客户端是如何自动配置的,配置了哪些东西.在自动 ...
- js中0.1+0.2 与0.3的对比
Math.abs(0.1+0.2-0.3)<=Number.EPSILON
- PLSQL登录的时候Warning提示:Using a filter for all users can lead to poor performance!
转自: https://blog.csdn.net/athena2015/article/details/81811908
- SAP云平台上的ABAP编程环境里如何消费第三方服务
在ABAP On-Premises环境下,使用ABAP编程消费第三方服务,相信很多ABAP顾问都已经非常熟悉了,无非就是使用CL_HTTP_CLIENT或者CL_REST_HTTP_CLIENT来发送 ...
- angular-cli 引入ui组件库
该例中使用的admin-lte以及bootstrap 1.使用npm 安装admin-lte命令: npm install admin-lte --save (--save的意思是将该以来写入到pa ...
- Linux 之 用户、用户组以及权限
拥有者(user),拥有组(group),其他人(other) 由于Linux是一个多人多任务的系统,因此经常会出现同一台机器同时有多个人进行操作,为了考虑每个人的隐私权以及每个人喜好的工作环境,所以 ...