当前位置:网站首页>51nod2884
51nod2884
2022-08-08 23:29:00 【Lqingyyyy】
水题 阿 就是先求出 最短路树 然后 从树的底端开始删点就好了
#include<iostream>
#include<queue>
#include<utility>
#include<cstring>
#include<algorithm>
#include<vector>
#define x first
#define y second
using namespace std;
const int N = 3e5 + 10,M = 2e6 + 10;
typedef long long ll;
typedef pair<ll,int> PII;
vector<vector<int> > v(N);
int head[N],to[M],last[M],w[M],cnt = 1;
void add(int a,int b,int c){
to[++cnt] = b;
w[cnt] = c;
last[cnt] = head[a];
head[a] = cnt;
}
int flag[N];ll dist[N],pre[N];
void dij(){
memset(dist,0x3f,sizeof dist);
priority_queue<PII,vector<PII>,greater<PII> >q;
q.push({
0,1});
dist[1] = 0;
while(q.size()){
PII p = q.top();
q.pop();
if(flag[p.y]) continue;
flag[p.y] = 1;
for(int i = head[p.y]; i != -1; i = last[i]){
int j = to[i];
if(dist[j] > dist[p.y] + w[i]){
dist[j] = dist[p.y] + w[i];
pre[j] = i;
q.push({
dist[j],j});
}
}
}
}
int dep[N];
void dfs(int x,int lastt){
dep[x] = dep[lastt] + 1;
for(auto j : v[x]){
if(j == lastt) continue;
dfs(j,x);
}
}
int main(){
int n,m,k;
cin >> n >> m >> k;
memset(head,-1,sizeof head);
for(int i = 1; i <= m; i++){
int x,y,w;
scanf("%d%d%d",&x,&y,&w);
add(x,y,w);
add(y,x,w);
}
dij();
for(int i = 2; i <= n; i++){
v[to[pre[i] ^ 1]].push_back(i);
}
dfs(1,0);
priority_queue<PII,vector<PII>,less<PII> > q;
for(int i = 2; i <= n; i++){
if(pre[i] != 0)
q.push({
dep[i],pre[i] / 2});
}
while(q.size() > k){
q.pop();
}
cout << min((int)q.size(),k) << endl;
while(q.size()){
printf("%d ",q.top().y);
q.pop();
}
return 0;
}
边栏推荐
- 如何搭建一套自己公司的知识共享平台
- 积性函数
- Learning experience of bp neural network
- stm32使用spi1在slave 模式下 dma 读取数据
- 线性筛求积性函数
- [GYCTF2020]Ezsqli-1|SQL注入
- Modal dialog is used to implement the sign-in
- Introduction to Qt (4) - Continuous playback of pictures (the use of two timers)
- 用工具实现 Mock API 的整个流程
- 2022杭电多校五 C - Slipper (dijkstra+虚拟结点)
猜你喜欢
(2022牛客多校五)G-KFC Crazy Thursday(二分+哈希/Manacher)
LightningChart .NET 10.3.2 Crack 支持旧项目直接升级
Analysis of WLAN - Wireless Local Area Network
Virtual router redundancy protocol VRRP - double-machine hot backup
STM8L 液晶数码管驱动,温度计液晶屏显示
meta learning
Learning experience of bp neural network
(2022牛客多校四)K-NIO‘s Sword(思维)
(2022牛客多校三)A-Ancestor(LCA)
如何使用 Eolink 实现 API 文档自动生成
随机推荐
Golang gorm 数据库连接,迁移,索引
待完善:tf.name_scope() 和 tf.variable_scope()的区别
【Verilog基础】PPA优化问题总结(含面积优化、速度优化)
微信小程序 wx:for 循环输出 例子
JSDay1-合并两个有序数组
PHP 类函数和对象函数
加载 已训练模型 张量的 几种方法
(2022牛客多校五)D-Birds in the tree(树形DP)
Porting ucos2 code from stm32 to GD32
最小生成树prim 求得 树上两点之间的最大最小值
2021 RoboCom 世界机器人开发者大赛-本科组(决赛)7-1绿色围栏(模拟)
(codeforce547)C-Mike and Foam(质因子+容斥原理)
2022牛客多校六 A-Array(构造+哈夫曼)
Master-slave delay reason and solution
Introduction to Qt (5) - file operation, hotkey and mouse reading (implementation of txt window)
Kubernetes 实现 CI/CD 发布流程
stm32 uses serial port to receive idle interrupt + dma to achieve variable length dma reception
(2022杭电多校三)1002-Boss Rush(状压DP+二分)
iptables firewall content full solution
启牛商学院靠不靠谱呢?证券账户开了安全吗