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< ...
随机推荐
- git删除分支步骤
在本地删除一个分支: git branch -D <本地分支> 在github远程端删除一个分支: git push origin :<远程端分支> 唯一不同的就是冒号代表了删 ...
- Codeforces Round #192 (Div. 2) (330A) A. Cakeminator
题意: 如果某一行没有草莓,就可以吃掉这一行,某一列没有也可以吃点这一列,求最多会被吃掉多少块蛋糕. //cf 192 div2 #include <stdio.h> #include & ...
- sift、surf、orb 特征提取及最优特征点匹配
目录 sift sift特征简介 sift特征提取步骤 surf surf特征简介 surf特征提取步骤 orb orb特征简介 orb特征提取算法 代码实现 特征提取 特征匹配 附录 sift si ...
- Zabbix在 windows下监控网卡
1.zabbix自定义监控Windows服务器的原理 Zabbix为Windows服务器的监控提供了PerfCounter(性能计数器)这个功能.Zabbix客户端通过PerfCounter获取Win ...
- Currency Exchange POJ1860
Description Several currency exchange points are working in our city. Let us suppose that each point ...
- LeetCode :2.两数相加 解题报告及算法优化思路
题目连接:2.两数相加 题意 题目难度标为 中等, 因为题意上有一部分理解难度,以及需要数据结构的链表基础. 还不知道到链表的童鞋可以粗略的看下百度百科或者是翻出数据结构的书看一看,通俗一点的语言来解 ...
- apicloud 开发环境搭建
之前做过appcan 手机应用的开发,工作需要切换的apicloud , 开发环境的的搭建是开发的第一步,let's go 1新建应用 step1 注册账号 注册apicloud 账号:https ...
- android——SQLite数据库存储(创建)
Android 专门提供了SQLiteOpenHelper帮助类,借助这个类就可以非常简单的对数据库进行创建和升级. 首先SQLiteOpenHelper是一个抽象类,在使用的时候需要创建一个自己的帮 ...
- 洛谷 P1939 矩阵加速(数列)
题意简述 \(a[1]=a[2]=a[3]=1\) \(a[x]=a[x−3]+a[x−1](x>3)\) 求a数列的第n项对1000000007取余的值. 题解思路 矩阵加速 设\[ F=\b ...
- Appium+python自动化(三十二)- 代码写死一时爽,框架重构火葬场 - PageObject+unittest(超详解)
简介 江湖有言:”代码写死一时爽,框架重构火葬场“,更有人戏言:”代码动态一时爽,一直动态一直爽