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,找到它所能改变的所 ...
随机推荐
- jsp 的 3 个编译指令
JSP 的编译指令是通知 JSP 引擎的消息,它不直接生成输出. 常见的编译指令有如下三个: 1.page:该指令是针对当前页面的指令 2.include:用于指定包含另一个页面 3.taglib:用 ...
- STL源码分析-priority_queue
http://note.youdao.com/noteshare?id=402cd1487d34af1a11f0daac6d16132f
- 单例 ------ C++实现
基础知识掌握: 单例考虑三点:内存何时释放.运行速度如何.多线程下能否保证只有一个实例 如果获取对象的返回值类型是引用,返回值赋值给变量而不是引用会进行对象的拷贝,这样就会出现两个对象,可以把显示声明 ...
- jquery ajax thinkphp异步局部刷新完整流程
环境:ThinkPHP3.2.3,jQuery3.2 前言: 在一般的网站中,都需要用到jquery或者其他框架(比如angular)来处理前后端数据交互,thinkphp在后台也内置了一些函数用 ...
- Tensorboard教程:高维向量可视化
Tensorflow高维向量可视化 觉得有用的话,欢迎一起讨论相互学习~Follow Me 参考文献 强烈推荐Tensorflow实战Google深度学习框架 实验平台: Tensorflow1.4. ...
- 用shell获取目录/文件夹/文件的时间戳
命令: date +%s -r 目录名/文件名 输出内容形如: 1276225332
- Codechef Dynamic Trees and Queries
Home » Practice(Hard) » Dynamic Trees and Queries Problem Code: ANUDTQSubmit https://www.codechef.co ...
- java网络传输数据
网络文件传输的问题,实际也是一种IO读写的基本问题.对于网络的文件数据写入到服务器的进程中,然后把进程中的网络IO系统传递到客户机,这个阶段,数据以字节流的形式保存.当该字节流被客户进程接受后,客户进 ...
- (值类型引用类型)和null的关系
1.null null表示变量没有指向任何对象. 2.值类型 包括 bool.结构体.枚举.int.double.float等等 .在.NET中值类型都继承自ValueType. 3. 引 ...
- vc 播放音乐
#include <vfw.h> #pragma comment(lib,"vfw32.lib") ● 简单实现 要实现一个播放器,首先要先建立一个MF ...