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的更多相关文章

  1. 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 ...

  2. Codeforces Round #617 (Div. 3)F. Berland Beauty

    题意: 给一棵树,边权未知,现在给m组约束,每组约束给出从u到v路径中的最小值,现在让你给出一组边权,使得符合之前的约束,不能给出输出-1 思路: 因为n较小,对于每组约束我们可以直接暴力修改路径上的 ...

  3. Codeforces Round #550 (Div. 3) F. Graph Without Long Directed Paths (二分图染色)

    题意:有\(n\)个点和\(m\)条无向边,现在让你给你这\(m\)条边赋方向,但是要满足任意一条边的路径都不能大于\(1\),问是否有满足条件的构造方向,如果有,输出一个二进制串,表示所给的边的方向 ...

  4. Codeforces Round #485 (Div. 2) F. AND Graph

    Codeforces Round #485 (Div. 2) F. AND Graph 题目连接: http://codeforces.com/contest/987/problem/F Descri ...

  5. Codeforces Round #486 (Div. 3) F. Rain and Umbrellas

    Codeforces Round #486 (Div. 3) F. Rain and Umbrellas 题目连接: http://codeforces.com/group/T0ITBvoeEx/co ...

  6. Codeforces Round #501 (Div. 3) F. Bracket Substring

    题目链接 Codeforces Round #501 (Div. 3) F. Bracket Substring 题解 官方题解 http://codeforces.com/blog/entry/60 ...

  7. 构造 Codeforces Round #Pi (Div. 2) B. Berland National Library

    题目传送门 /* 题意:给出一系列读者出行的记录,+表示一个读者进入,-表示一个读者离开,可能之前已经有读者在图书馆 构造:now记录当前图书馆人数,sz记录最小的容量,in数组标记进去的读者,分情况 ...

  8. Codeforces Round #499 (Div. 1) F. Tree

    Codeforces Round #499 (Div. 1) F. Tree 题目链接 \(\rm CodeForces\):https://codeforces.com/contest/1010/p ...

  9. Codeforces 1005 F - Berland and the Shortest Paths

    F - Berland and the Shortest Paths 思路: bfs+dfs 首先,bfs找出1到其他点的最短路径大小dis[i] 然后对于2...n中的每个节点u,找到它所能改变的所 ...

随机推荐

  1. 手脱tElock 0.98b1 -> tE!

    声明: 只为纪录自己的脱壳历程,高手勿喷 第一种:两次内存法 注: ①这是在win7x32系统上运行的脱壳,所以可能地址不同 ②修复的时候用等级三修复,最后修复不了的剪切掉然后转存合一正常运行,已测试 ...

  2. 通过socket实现多个连接并实现ssh功能

    一.前言 上一篇中我们已经知道了客户端通过socket来连接服务端,进行了一次数据传输,那如何实现客户端多次发生数据?而服务端接受多个客户端呢? 二.发送中文信息 在python3中,socket只能 ...

  3. python 获取文件md5

    def GetFileMd5(filename): if not os.path.isfile(filename): return myhash = hashlib.md5() f = file(fi ...

  4. mysql cpu 占用高

    vi /etc/my.cnf [mysqld]tmp_table_size=200M mysql> show global status like ‘created_tmp%‘; +—————— ...

  5. 你知道吗?衡量 Web 性能的几个关键指标

    自网站诞生以来,响应速度/响应时间一直都是大家关心的话题,而速度慢乃是网站的一个杀手,正当大家以为四核和宽带能力的提升能够解决这些问题时,Wi-Fi和移动设备为热点移动互联网又悄然兴起. 在2006年 ...

  6. c++ poco 使用mysql中文乱码问题

    poco 是c++ 一个比较好的库,现在正在学习使用它,碰到一些问题记录在此. poco版本:poco-1.46-all ,带有数据库的支持模块 操作系统:ubuntu 1.使用poco的MySQL模 ...

  7. oozie与sqoop的简单案例

    1:拷贝模板 2:拷贝hive用的jar包 方式一: 3:编辑job.properties # # Licensed to the Apache Software Foundation (ASF) u ...

  8. Spring整合Quartz分布式调度

    前言 为了保证应用的高可用和高并发性,一般都会部署多个节点:对于定时任务,如果每个节点都执行自己的定时任务,一方面耗费了系统资源,另一方面有些任务多次执行,可能引发应用逻辑问题,所以需要一个分布式的调 ...

  9. 【NOIP2013提高组T3】加分二叉树

    题目描述 设一个n个节点的二叉树tree的中序遍历为(1,2,3,…,n),其中数字1,2,3,…,n为节点编号.每个节点都有一个分数(均为正整数),记第i个节点的分数为di,tree及它的每个子树都 ...

  10. 【leetcode 简单】第三题 回文数

    判断一个整数是否是回文数.回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数. 示例 1: 输入: 121 输出: true 示例 2: 输入: -121 输出: false 解释: 从左向 ...