codeforces 303 div2 E
赤裸裸的最短路,需要注意下枚举过程就好了。直接贴上别人的代码,发现他的代码挺符合我的风格,以后就这样写了。
#include <bits/stdc++.h>
using namespace std;
struct node{
int y,z,id;
node(){}
node(int y,int z,int id):y(y),z(z),id(id){}
};
vector<node> e[];
int n,m,u;
int f[];
int ed[];
long long dis[];
vector<int> ans;
const long long inf = (long long)*;
int main(){
cin >>n >>m;
for (int i=;i<=m;i++){
int x,y,z;
cin >> x>>y>>z;
ed[i]=z;
e[x].push_back(node(y,z,i));
e[y].push_back(node(x,z,i));
}
cin >> u;
queue<int> q;
q.push(u);
for (int i=;i<=n;i++) dis[i]=inf;
//for (int i=1;i<=n;i++) cout<<dis[i]<<endl;
dis[u]=;
while (!q.empty()){
int now = q.front();
q.pop();
for (int i=;i<e[now].size();i++){
int v = e[now][i].y;
if (dis[now]+e[now][i].z<dis[v] || dis[now]+e[now][i].z==dis[v] && e[now][i].z<ed[f[v]]){
f[v]=e[now][i].id;
dis[v]=dis[now]+e[now][i].z;
q.push(v);
}
}
}
long long cnt=;
for (int i=;i<=n;i++)
if (f[i]!=) cnt+=ed[f[i]],ans.push_back(f[i]);
sort(ans.begin(),ans.end());
cout << cnt<<endl;
for(int i=;i<ans.size();i++){
if (i>) cout<<" ";
cout << ans[i];
}
return ;
}
codeforces 303 div2 E的更多相关文章
- Codeforces #180 div2 C Parity Game
// Codeforces #180 div2 C Parity Game // // 这个问题的意思被摄物体没有解释 // // 这个主题是如此的狠一点(对我来说,),不多说了这 // // 解决问 ...
- Codeforces #541 (Div2) - E. String Multiplication(动态规划)
Problem Codeforces #541 (Div2) - E. String Multiplication Time Limit: 2000 mSec Problem Descriptio ...
- Codeforces #541 (Div2) - F. Asya And Kittens(并查集+链表)
Problem Codeforces #541 (Div2) - F. Asya And Kittens Time Limit: 2000 mSec Problem Description Inp ...
- Codeforces #541 (Div2) - D. Gourmet choice(拓扑排序+并查集)
Problem Codeforces #541 (Div2) - D. Gourmet choice Time Limit: 2000 mSec Problem Description Input ...
- Codeforces #548 (Div2) - D.Steps to One(概率dp+数论)
Problem Codeforces #548 (Div2) - D.Steps to One Time Limit: 2000 mSec Problem Description Input Th ...
- 【Codeforces #312 div2 A】Lala Land and Apple Trees
# [Codeforces #312 div2 A]Lala Land and Apple Trees 首先,此题的大意是在一条坐标轴上,有\(n\)个点,每个点的权值为\(a_{i}\),第一次从原 ...
- Codeforces #263 div2 解题报告
比赛链接:http://codeforces.com/contest/462 这次比赛的时候,刚刚注冊的时候非常想好好的做一下,可是网上喝了个小酒之后.也就迷迷糊糊地看了题目,做了几题.一觉醒来发现r ...
- codeforces #round363 div2.C-Vacations (DP)
题目链接:http://codeforces.com/contest/699/problem/C dp[i][j]表示第i天做事情j所得到最小的假期,j=0,1,2. #include<bits ...
- codeforces round367 div2.C (DP)
题目链接:http://codeforces.com/contest/706/problem/C #include<bits/stdc++.h> using namespace std; ...
随机推荐
- jquery 选择器包含特殊字符
选择器包含 : .# ( ] 等等 比如 <div id="id#a"></div> <div id="id[1]">< ...
- [转]VC中调用外部exe程序方式
本文转自:http://blog.sina.com.cn/s/blog_486285690100ljwu.html 目前知道三种方式:WinExec,ShellExecute ,CreateProce ...
- fedora kde桌面系统配置
本文向大家分享个人将fedora操作系统作为工作生活首选桌面系统的一些配置经验,系统版本与fedora最新版本保持一致,当前为fedora 25. #添加rpm源su -c 'dnf install ...
- vue项目中常用的一些公共方法
//校验手机号码 export function isSpecialPhone(num) { return /^1[2,3,4,5,7,8]\d{9}$/.test(num) } //校验中英文姓名 ...
- 登录脚本重构Element
登录脚本重构Element package com.gubai.selenium; import org.openqa.selenium.By; import org.openqa.selenium. ...
- codeforces 235 B lets play osu!
cf235B 一道有意思的题.(据说是美少女(伪)计算机科学家出的,hh) 根据题目要求,就是求ni^2的和. 而n^2=n*(n-1)+n; n*(n-1)=C(n,2)*2: 所以∑ai^2=∑a ...
- vscode 用户代码片段 vue初始化模板 Snippet #新加入开头注释 自动生成文件名 开发日期时间等内容
vue文件模板 模板变量 https://code.visualstudio.com/docs/editor/userdefinedsnippets#_variables vue.json { // ...
- k8s集群之Docker安装镜像加速器配置与k8s容器网络
安装Docker 参考:https://www.cnblogs.com/rdchenxi/p/10381631.html 加速器配置 参考:https://www.cnblogs.com/rdchen ...
- 使用SpringBoot-JPA进行自定义的保存及批量保存
更多精彩博文,欢迎访问我的个人博客 说明 SpringBoot版本:2.1.4.RELEASE java版本:1.8 文中所说JPA皆指spring-boot-starter-data-jpa 使用J ...
- caffe layer注册机制
Caffe内部维护一个注册表用于查找特定Layer对应的工厂函数(Layer Factory的设计用到了设计模式里的工厂模式).Layer_factory的主要作用是负责Layer的注册,已经注册完事 ...