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.你可以在这当中任意选择任意多个物品. ...
随机推荐
- High load average analyze
https://www.tummy.com/articles/isolating-heavy-load/ https://www.tecmint.com/understand-linux-load-a ...
- React Hooks中父组件中调用子组件方法
React Hooks中父组件中调用子组件方法 使用到的hooks-- useImperativeHandle,useRef /* child子组件 */ // https://reactjs.org ...
- php json_encode() 中文保留
这几天遇到了一个问题 给java传json的时候 没有处理中文 那边拿数据的时候说不是中文的 需要转一下 方法: 实际应用中,当有中文字符时,当直接使用json_encode() 函数会使汉字不 ...
- hdu 1045 要求全部逐一搜索完的深搜
#include<stdio.h> #include<string.h> int visit[10][10]; char map[10][10]; int n,ans,ss,t ...
- Python之Django
一.Django是一个开放源代码的Web应用框架,由Python写成.采用了MTV的框架模式,即模型M,视图V和模版T.它最初是被开发来用于管理劳伦斯出版集团旗下的一些以新闻内容为主的网站的,即是CM ...
- 笔记 - C#从头开始构建编译器 - 2
视频与PR:https://github.com/terrajobst/minsk/blob/master/docs/episode-02.md 作者是 Immo Landwerth(https:// ...
- Java 面向对象_多态
多态图解 代码中体现多态性 父类名称 对象名 = new 子类名称(); or 接口名称 对象名 = new 实现类名称(); // 父类 public class Father { public v ...
- 【转载】程序设计过程中SQL语句Where 1=1的作用
在Asp.Net网站或者Java网站的程序设计的过程中,很多时候我们可以看到拼接SQL语句的写法的时候都可以看到最前面有个Where 1=1这个条件,其实Where 1=1这是个恒等式,SQL语句写成 ...
- FreeRTOS 任务创建和删除(动态)
TaskHandle_t taskhandle; TaskHandle_t taskhandle1; void vTask(void *t) { int i = 0; while(1) { i++; ...
- [LeetCode] 1029. 两地调度 ☆(贪心)
官方题解 作差排序 描述 公司计划面试 2N 人.第 i 人飞往 A 市的费用为 costs[i][0],飞往 B 市的费用为 costs[i][1]. 返回将每个人都飞到某座城市的最低费用,要求每个 ...