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. lnmp集成环境tp nginx vhost配置

    server { listen 80; server_name xxx; charset utf-8; root /home/wwwroot/axxx/public; index index.html ...

  2. 12.UiAutomator 获取系统信息

    一.Build构建信息 1.build类: Build类提供了硬件厂商.编号.序列号.SDK版本等重要信息. 类名:android.os.Build 常量名 说明 BOARD 底层板名称 BOOTLO ...

  3. 深入分析Java中的 == 和equals

    关于Java中的 == 和equals的解释请看这位博主的文章 :http://www.cnblogs.com/dolphin0520/p/3592500.html 以下是我对这篇文章的一些扩展. 对 ...

  4. 【POJ】2142 The Balance 数论(扩展欧几里得算法)

    [题意]给定a,b,c,在天平左边放置若干重量a的砝码,在天平右边放置若干重量b的砝码,使得天平两端砝码差为c.设放置x个A砝码和y个B砝码,求x+y的最小值. [算法]数论(扩展欧几里德算法) [题 ...

  5. Java 9 中的 9 个新特性

    Java 8 发布三年多之后,java9已经发布了 . 你可能已经听说过 Java 9 的模块系统,但是这个新版本还有许多其它的更新. 这里有九个令人兴奋的新功能将与 Java 9 一起发布.   1 ...

  6. /i,/m,/s,/x,/A,/s,/U,/x,/j,/u 等正则修饰符用法~

    i (PCRE_CASELESS) 如果设置了这个修饰符,模式中的字母会进行大小写不敏感匹配. m (PCRE_MULTILINE) 默认情况下,PCRE 认为目标字符串是由单行字符组成的(然而实际上 ...

  7. HDU 1059 Dividing (dp)

    题目链接 Problem Description Marsha and Bill own a collection of marbles. They want to split the collect ...

  8. JavaScript实现水平进度条拖拽效果

    <html> <head> <meta charset="UTF-8"> <title>Document</title> ...

  9. Linux 上配置 NTP SERVER

    在CENTOS 6.2上面安装配置NTP SERVER 安装NTP:yum install ntp 配置时间源vi /etc/ntp.confserver 210.72.145.44server nt ...

  10. HDU 6187 Destroy Walls (对偶图最小生成树)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6187 题意:有一个V个结点M条边的带边权无向平面图,有一个人在一个区域,要拆一些墙使得他可以到达任意一 ...