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< ...
随机推荐
- 【iOS】UIImageView 点击事件
UIImageView 并不像 UIButton 那样点击鼠标就可以关联点击事件,也不像 Android 里有 onClickListener,这个时候就需要借助 UITapGestureRecogn ...
- postman使用pre-request script计算md5
接口加了验签逻辑,具体是md5(salt+时间戳).被某君吐槽说测试不方便啊能不能先关掉.其实没有必要打开又关闭验签功能,postman的pre-request script功能完全可以模拟客户端加密 ...
- 注解与AOP切面编程实现redis缓存与数据库查询的解耦
一般缓存与数据库的配合使用是这样的. 1.查询缓存中是否有数据. 2.缓存中无数据,查询数据库. 3.把数据库数据插入到缓存中. 其实我们发现 1,3 都是固定的套路,只有2 是真正的业务代码.我们可 ...
- 数据结构-二叉搜索树和二叉树排序算法(python实现)
今天我们要介绍的是一种特殊的二叉树--二叉搜索树,同时我们也会讲到一种排序算法--二叉树排序算法.这两者之间有什么联系呢,我们一起来看一下吧. 开始之前呢,我们先来介绍一下如何创建一颗二叉搜索树. 假 ...
- [TCP/IP]DNS解析
DNS解析主机的IP地址 host -t A www.baidu.com
- cinder支持nfs快照
[问题描述] cinder后端设置为NFS,磁盘创建快照失败. 日志里面发现了这个错误: VolumeDriverException: Volume driver reported an error: ...
- 微信公众号发送消息给用户 php
1.微信公众号 这里得话 一开始先去看了 微信公众号的接口 发现网页授权需要时认证的服务号,一开始想的是那去申请一个认证的服务号岂不是很费事,然后网上搜了搜,发现了还有微信公众号个人测试号这个东西,所 ...
- android ——后台下载
这次的这个demo想要实现一个后台下载文件的功能,下载的时候会有一个告知进度的通知, 使用的依赖库就一个: compile 'com.squareup.okhttp3:okhttp:3.9.0' 大体 ...
- 【Python3爬虫】学习分布式爬虫第一步--Redis分布式爬虫初体验
一.写在前面 之前写的爬虫都是单机爬虫,还没有尝试过分布式爬虫,这次就是一个分布式爬虫的初体验.所谓分布式爬虫,就是要用多台电脑同时爬取数据,相比于单机爬虫,分布式爬虫的爬取速度更快,也能更好地应对I ...
- socket基于TCP(粘包现象和处理)
目录 6socket套接字 7基于TCP协议的socket简单的网络通信 AF_UNIX AF_INET(应用最广泛的一个) 报错类型 单一 链接+循环通信 远程命令 9.tcp 实例:远程执行命令 ...