CodeForces 507E Breaking Good 2维权重dij
#include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define lch(x) tr[x].son[0]
#define rch(x) tr[x].son[1]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const LL _INF = 0xc0c0c0c0c0c0c0c0;
const LL mod = (int)1e9+;
const int N = 1e5 + ;
vector<pll> vc[N];
struct Node{
int o, u, d, p;
bool operator < (const Node & x) const{
if(d == x.d) return p > x.p;
return d > x.d;
}
};
int pre[N];
int vis[N];
priority_queue<Node> pq;
void dij(){
pq.push({, , , });
while(!pq.empty()){
Node t = pq.top();
pq.pop();
if(vis[t.u]) continue;
vis[t.u] = ;
pre[t.u] = t.o;
for(pll tmp : vc[t.u]){
if(vis[tmp.fi]) continue;
pq.push({t.u, tmp.fi, t.d+, t.p + !tmp.se});
}
}
}
vector<Node> ans;
int fpre[N];
int main(){
int n, m, u, v, op;
scanf("%d%d", &n, &m);
for(int i = ; i <= m; ++i){
scanf("%d%d%d", &u, &v, &op);
vc[u].pb(pll(v, op));
vc[v].pb(pll(u, op));
}
dij();
int x = n;
while(x){
fpre[x] = pre[x];
x = pre[x];
}
for(int i = ; i <= n; ++i){
for(pll &t : vc[i]){
if(t.fi < i){
int v = t.fi;
if((fpre[i] == v || fpre[v] == i)){
if(!t.se)
ans.pb({v, i, , });
}
else if(t.se)
ans.pb({v, i, , });
}
}
}
printf("%d\n", ans.size());
for(Node & t : ans){
printf("%d %d %d\n", t.o, t.u, t.d);
}
return ;
}
CodeForces 507E Breaking Good 2维权重dij的更多相关文章
- [Codeforces 507E] Breaking Good
[题目链接] https://codeforces.com/contest/507/problem/E [算法] 首先BFS求出1到其余点的最短路 , N到其余点的最短路,记为distA[]和dist ...
- 【codeforces 507E】Breaking Good
[题目链接]:https://vjudge.net/contest/164884#problem/D [题意] 给你一张图; 图中有些路是完好的;但有些路还没修好; 先不管路有没有修好; 问你从起点到 ...
- Codeforces 707 E. Garlands (二维树状数组)
题目链接:http://codeforces.com/problemset/problem/707/E 给你nxm的网格,有k条链,每条链上有len个节点,每个节点有一个值. 有q个操作,操作ask问 ...
- Codeforces 835C - Star sky - [二维前缀和]
题目链接:http://codeforces.com/problemset/problem/835/C 题意: 在天空上划定一个直角坐标系,有 $n$ 颗星星,每颗星星都有坐标 $(x_i,y_i)$ ...
- Codeforces Round #439 (Div. 2) Problem E (Codeforces 869E) - 暴力 - 随机化 - 二维树状数组 - 差分
Adieu l'ami. Koyomi is helping Oshino, an acquaintance of his, to take care of an open space around ...
- codeforces 14E. Camels(多维dp)
题目链接:http://codeforces.com/problemset/problem/14/E 题意:就是给出n个点要求画出t个波峰和t-1个波谷 很显然要t个波峰和t-1个波谷开始是波动一定是 ...
- B - Legacy CodeForces - 787D 线段树优化建图+dij最短路 基本套路
B - Legacy CodeForces - 787D 这个题目开始看过去还是很简单的,就是一个最短路,但是这个最短路的建图没有那么简单,因为直接的普通建图边太多了,肯定会超时的,所以要用线段树来优 ...
- Codeforces 450D Jzzhu and Cities [heap优化dij]
#include<bits/stdc++.h> #define MAXN 100050 #define MAXM 900000 using namespace std; struct st ...
- Codeforces 838A - Binary Blocks(二维前缀和+容斥)
838A - Binary Blocks 思路:求一下前缀和,然后就能很快算出每一小正方块中1的个数了,0的个数等于k*k减去1的个数,两个的最小值就是要加进答案的值. 代码: #include< ...
随机推荐
- druid0.15.0安装方式
Druid0.15.0安装文档 1 集群规划 Master包含Coordinator和Overlord,4核16G*2: data包含Historical和MiddleManager,16核64G*3 ...
- __int64与long long、long的区别
首先来看一看int.long.long long的取值范围 int 所占字节数为:4 表示范围为:-2147483648~2147 ...
- thinkphp3.2使用七牛云上传文件
最近项目中用到了七牛云服务,来分享一下thinkphp使用七牛云来进行文件上传 1.首先在七牛云创建一个空间,例如空间名为test.获取secrectKey,accessKey 2.在thinkphp ...
- C程序设计(第四版)课后习题完整版 谭浩强编著
//复习过程中,纯手打,持续更新,觉得好就点个赞吧. 第一章:程序设计和C语言 习题 1.什么是程序?什么是程序设计? 答:程序就是一组计算机能识别和执行的指令.程序设计是指从确定任务到得到结果,写出 ...
- python 字符串格式化format
通过{}和:来代替传统%方式 1.位置参数 位置参数不受顺序约束,且可以为{},只要format里有相对应的参数值即可,参数索引从0开,传入位置参数列表可用*列表 >>> li ...
- 用HTML5的Audio标签做一个歌词同步的效果
HTML5出来这么久了,但是关于它里面的audio标签也就用过那么一次,当然还仅仅只是把这个标签插入到了页面中.这次呢就刚好趁着帮朋友做几个页面,拿这个audio标签来练练手. 首先你需要向页面中插入 ...
- [Spring cloud 一步步实现广告系统] 14. 全量索引代码实现
上一节我们实现了索引基本操作的类以及索引缓存工具类,本小节我们开始实现加载全量索引数据,在加载全量索引数据之前,我们需要先将数据库中的表数据导出到一份文件中.Let's code. 1.首先定义一个常 ...
- Thread、ThreadPool、Task、Parallel、Async和Await基本用法、区别以及弊端
多线程的操作在程序中也是比较常见的,比如开启一个线程执行一些比较耗时的操作(IO操作),而主线程继续执行当前操作,不会造成主线程阻塞.线程又分为前台线程和后台线程,区别是:整个程序必须要运行完前台线程 ...
- websql操作类封装
在之前,我写了一个websql的封装类库,代码如下: (function(win) { function smpWebSql(options){ options = options || {}; th ...
- 「雕爷学编程」Arduino动手做(10)——敲击传感器模块
37款传感器和模块的提法,在网络上广泛流传,其实Arduino能够兼容的传感器模块肯定是不止37种的.鉴于本人手头积累了一些传感器与模块,依照实践出真知(动手试试)的理念,以学习和交流为目的,这里准备 ...