这题不错...

首先,不难看到他想让你求出的是最短路树

然后,考虑到所有边权均为1,所以可以采用bfs直接生成最短路树

至于方案的储存,可以在加边的时候同时记录边的编号,然后对每个点维护一个能转移他的最短路的边的编号的集合,这样总的方案数就是所有的集合大小的乘积

然后用dfs在每个集合中选一个元素输出即可

#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
using namespace std;
struct Edge
{
int next;
int to;
int num;
}edge[];
int head[];
int dep[];
vector <int> v[];
int used[];
int cnt=;
int n,m,k;
void init()
{
memset(head,-,sizeof(head));
cnt=;
}
void add(int l,int r,int v)
{
edge[cnt].next=head[l];
edge[cnt].to=r;
edge[cnt].num=v;
head[l]=cnt++;
}
void bfs(int rt)
{
queue <int> M;
M.push(rt);
dep[rt]=;
while(!M.empty())
{
int u=M.front();
M.pop();
for(int i=head[u];i!=-;i=edge[i].next)
{
int to=edge[i].to;
if(!dep[to])
{
dep[to]=dep[u]+;
v[to].push_back(edge[i].num);
M.push(to);
}else if(dep[to]==dep[u]+)
{
v[to].push_back(edge[i].num);
}
}
}
}
int cct=,tot=;
void dfs(int dep)
{
if(dep==n+)
{
for(int i=;i<=m;i++)
{
printf("%d",used[i]);
}
printf("\n");
cct++;
if(cct==tot)
{
exit();
}
return;
}
for(int i=;i<v[dep].size();i++)
{
used[v[dep][i]]=;
dfs(dep+);
used[v[dep][i]]=;
}
}
inline int read()
{
int f=,x=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int main()
{
n=read(),m=read(),k=read();
init();
for(int i=;i<=m;i++)
{
int x=read(),y=read();
add(x,y,i);
add(y,x,i);
}
bfs();
for(int i=;i<=n;i++)
{
if((long long)tot*v[i].size()>k)
{
tot=k;
break;
}else
{
tot*=v[i].size();
}
}
printf("%d\n",tot);
dfs();
return ;
}

CF1005F的更多相关文章

  1. CF1005F Berland and the Shortest Paths

    \(\color{#0066ff}{ 题目描述 }\) 一个无向图(边权为1),输出一下选边的方案使\(\sum d_i\)最小(\(d_i\)为从1到i的最短路) 输出一个方案数和方案(方案数超过k ...

  2. CF1005F Berland and the Shortest Paths (树上构造最短路树)

    题目大意:给你一个边权为$1$的无向图,构造出所有$1$为根的最短路树并输出 性质:单源最短路树上每个点到根的路径 ,一定是这个点到根的最短路之一 边权为$1$,$bfs$出单源最短路,然后构建最短路 ...

  3. CF1005F Berland and the Shortest Paths 最短路树计数

    问题描述 LG-CF1005F 题解 由题面显然可得,所求即最短路树. 所以跑出最短路树,计数,输出方案即可. \(\mathrm{Code}\) #include<bits/stdc++.h& ...

  4. [CF1005F]Berland and the Shortest Paths_最短路树_堆优化dij

    Berland and the Shortest Paths 题目链接:https://www.codeforces.com/contest/1005/problem/F 数据范围:略. 题解: 太鬼 ...

随机推荐

  1. 【mmall】mybatis三剑客

    mybatis-generator mybatis-plugin Mybatis Plugin插件安装破解及使用:http://blog.csdn.net/u011410529/article/det ...

  2. MSSQL无法启动-原来电脑登录密码改了,重启后要设置

    Sql Server (MSSQLSERVER) 服务无法启动 - 晓菜鸟 - 博客园  http://www.cnblogs.com/52XF/p/4230578.html  --摘抄如下: 一.是 ...

  3. Spring4之AOP

    [www.dev1234.com]一头扎进Spring4视频教程\一头扎进Spring4源码\[www.java1234.com]<一头扎进Spring4>第七讲 源码 [www.dev1 ...

  4. telnet能通但是ping不通

    以前本人以为Telnet通 ping一定也是通的, telnet能通,表示两台计算机之间建立了连接通道.理论上是能ping通的.如果不能ping通,可能的原因是对方主机关闭了ping回显,或者是对方的 ...

  5. 【转载】AutoML--超参数调优之Bayesian Optimization

    原文:Auto Machine Learning笔记 - Bayesian Optimization 优化器是机器学习中很重要的一个环节.当确定损失函数时,你需要一个优化器使损失函数的参数能够快速有效 ...

  6. ssh连接报错server responded”algorithm negotiation failed”

    ssh工具版本太低,OpenSSL版本升的比较高,有些算法不支持. 解决方法: 1.修改ssh的配置文件 /etc/ssh/sshd_config cd /etc/sshvi /etc/ssh/ssh ...

  7. Jquery的一些常见用法

    谨以此文怀念我们大学的时光,Jquery3.4.0下载 https://code.jquery.com/jquery-3.4.0.min.js ⒈常用方法 $("#div1").h ...

  8. 【windows下进程searchfilterhost.exe分析】

    searchfilterhost.exe [进程信息] 进程文件: searchfilterhost.exe 进程名称: n/a 英文描述: searchfilterhost.exe is a pro ...

  9. 纪念一下我对Kalman的无限崇拜之情

    今天用Kalman来求线性预测模型的系数,和LMS一对比,天啦噜,我感叹了半小时... 和LMS需要选合适的步长,样本序列需要足够长,迭代次数需要足够多,相比,卡尔曼真是帅呆了!不需要步长!不需要蒙特 ...

  10. OninitDialog与OnCreate两个消息有何区别

    WM_INITDIALOGThe WM_INITDIALOG message is sent to the dialog box procedure immediately before a dial ...