Codeforces Round #496 (Div. 3) F - Berland and the Shortest Paths
F - Berland and the Shortest Paths
思路:还是很好想的,处理出来最短路径图,然后搜k个就好啦。
#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define pii pair<int, int> using namespace std; const int N = 5e5 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = ; int n, m, k, tot, d[N], head[N], ans[N];
LL cnt;
struct node {
int u, v, nx;
} edge[N]; void add(int u, int v) {
edge[tot].u = u;
edge[tot].v = v;
edge[tot].nx = head[u];
head[u] = tot++;
} vector<int> vec[N]; void bfs() {
queue<int> que;
d[] = ;
que.push(); while(!que.empty()) {
int u = que.front(); que.pop();
for(int i = head[u]; ~i; i = edge[i].nx) {
int v = edge[i].v;
if(d[v] != -) continue;
d[v] = d[u] + ;
que.push(v);
}
}
} void dfs(int pos) {
if(cnt <= ) return;
if(pos == n + ) {
cnt--;
for(int i = ; i <= m; i++)
printf("%d", ans[i]);
puts("");
return;
}
for(int i = ; i < vec[pos].size(); i++) {
ans[vec[pos][i]] = ;
dfs(pos + );
ans[vec[pos][i]] = ;
}
}
int main(){
memset(head, -, sizeof(head));
scanf("%d%d%d", &n, &m, &k);
for(int i = ; i <= m; i++) {
int u, v; scanf("%d%d", &u, &v);
add(u, v);
add(v, u);
} memset(d, -, sizeof(d)); bfs();
for(int i = ; i < tot; i++) {
int u = edge[i].u, v = edge[i].v;
if(d[u] + == d[v]) {
vec[v].push_back(i / + );
}
} cnt = ;
for(int i = ; i <= n; i++) {
cnt *= (int) vec[i].size();
if(cnt >= k) break;
} cnt = min(cnt, 1ll * k);
printf("%lld\n", cnt);
dfs();
return ;
} /*
*/
Codeforces Round #496 (Div. 3) F - Berland and the Shortest Paths的更多相关文章
- Codeforces Round #550 (Div. 3) F. Graph Without Long Directed Paths
F. Graph Without Long Directed Paths time limit per test 2 seconds memory limit per test 256 ...
- Codeforces Round #617 (Div. 3)F. Berland Beauty
题意: 给一棵树,边权未知,现在给m组约束,每组约束给出从u到v路径中的最小值,现在让你给出一组边权,使得符合之前的约束,不能给出输出-1 思路: 因为n较小,对于每组约束我们可以直接暴力修改路径上的 ...
- Codeforces Round #550 (Div. 3) F. Graph Without Long Directed Paths (二分图染色)
题意:有\(n\)个点和\(m\)条无向边,现在让你给你这\(m\)条边赋方向,但是要满足任意一条边的路径都不能大于\(1\),问是否有满足条件的构造方向,如果有,输出一个二进制串,表示所给的边的方向 ...
- Codeforces Round #485 (Div. 2) F. AND Graph
Codeforces Round #485 (Div. 2) F. AND Graph 题目连接: http://codeforces.com/contest/987/problem/F Descri ...
- Codeforces Round #486 (Div. 3) F. Rain and Umbrellas
Codeforces Round #486 (Div. 3) F. Rain and Umbrellas 题目连接: http://codeforces.com/group/T0ITBvoeEx/co ...
- Codeforces Round #501 (Div. 3) F. Bracket Substring
题目链接 Codeforces Round #501 (Div. 3) F. Bracket Substring 题解 官方题解 http://codeforces.com/blog/entry/60 ...
- 构造 Codeforces Round #Pi (Div. 2) B. Berland National Library
题目传送门 /* 题意:给出一系列读者出行的记录,+表示一个读者进入,-表示一个读者离开,可能之前已经有读者在图书馆 构造:now记录当前图书馆人数,sz记录最小的容量,in数组标记进去的读者,分情况 ...
- Codeforces Round #499 (Div. 1) F. Tree
Codeforces Round #499 (Div. 1) F. Tree 题目链接 \(\rm CodeForces\):https://codeforces.com/contest/1010/p ...
- Codeforces 1005 F - Berland and the Shortest Paths
F - Berland and the Shortest Paths 思路: bfs+dfs 首先,bfs找出1到其他点的最短路径大小dis[i] 然后对于2...n中的每个节点u,找到它所能改变的所 ...
随机推荐
- sql命令创建数据库
mysql create database 指定utf-8编码 CREATE DATABASE IF NOT EXISTS thinkphp DEFAULT CHARSET utf8 COLLATE ...
- [吴恩达机器学习笔记]12支持向量机6SVM总结
12.支持向量机 觉得有用的话,欢迎一起讨论相互学习~Follow Me 12.6SVM总结 推荐使用成熟的软件包 用以解决 SVM 最优化问题的软件很复杂,且已经有研究者做了很多年数值优化.因此强烈 ...
- HashSet的特性介绍
HashSet除了在元素的存储上是无序的以外,还是不能够存储重复的元素. HashSet如何判断元素是否重复呢?是根据元素继承的两个方法来判断,hashCode和equals,当存储元素时,首先判断要 ...
- 【BZOJ】1875: [SDOI2009]HH去散步 矩阵快速幂
[题意]给定n个点m边的无向图,求A到B恰好经过t条边的路径数,路径须满足每条边都和前一条边不同.n<=20,m<=60,t<=2^30. [算法]矩阵快速幂 [题解]将图的邻接矩阵 ...
- 在iOS开发中如何播放视频
技术博客http://www.cnblogs.com/ChenYilong/ 新浪微博http://weibo.com/luohanchenyilong 如何播放视频 •iOS提供了叫做MPMo ...
- NYOJ 756 重建二叉树 (二叉树)
题目链接 描述 题目很简单,给你一棵二叉树的后序和中序序列,求出它的前序序列(So easy!). 输入 输入有多组数据(少于100组),以文件结尾结束.每组数据仅一行,包括两个字符串,中间用空格隔开 ...
- 爬虫--selenium
什么是selenium? 基本使用 from selenium import webdriver from selenium.webdriver.common.by import By from se ...
- vista风格的cms企业html后台管理系统模板——后台
链接:http://pan.baidu.com/s/1c1Cv99e 密码:20yz
- 图片异或(xor)getflag
题目地址:https://files.cnblogs.com/files/nul1/flag_enc.png.tar 这题是源于:网鼎杯minified 经过测试隧道红色最低通道异常.其余均正常.所以 ...
- 南邮PHP反序列化
题目如下: <?php class just4fun { var $enter; var $secret; } if (isset($_GET['pass'])) { $pass = $_GET ...