CF1005F
这题不错...
首先,不难看到他想让你求出的是最短路树
然后,考虑到所有边权均为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的更多相关文章
- CF1005F Berland and the Shortest Paths
\(\color{#0066ff}{ 题目描述 }\) 一个无向图(边权为1),输出一下选边的方案使\(\sum d_i\)最小(\(d_i\)为从1到i的最短路) 输出一个方案数和方案(方案数超过k ...
- CF1005F Berland and the Shortest Paths (树上构造最短路树)
题目大意:给你一个边权为$1$的无向图,构造出所有$1$为根的最短路树并输出 性质:单源最短路树上每个点到根的路径 ,一定是这个点到根的最短路之一 边权为$1$,$bfs$出单源最短路,然后构建最短路 ...
- CF1005F Berland and the Shortest Paths 最短路树计数
问题描述 LG-CF1005F 题解 由题面显然可得,所求即最短路树. 所以跑出最短路树,计数,输出方案即可. \(\mathrm{Code}\) #include<bits/stdc++.h& ...
- [CF1005F]Berland and the Shortest Paths_最短路树_堆优化dij
Berland and the Shortest Paths 题目链接:https://www.codeforces.com/contest/1005/problem/F 数据范围:略. 题解: 太鬼 ...
随机推荐
- 🍓 JRoll、React滑动删除 🍓
import React, { Component } from 'react'; import '../src/css/reset.css'; import '../src/css/delete.c ...
- markdown自动生成侧边栏TOC /目录
http://blog.csdn.net/haleypku/article/details/51226704 此文可以只了解一下概念: http://i5ting.github.io/i5ting_z ...
- MySql cmd下的学习笔记 —— 有关子查询的操作(where型,from型,exists型子查询)
先找到goods表 查询goods_id最大的商品 where型的子查询 查询goods_id最大的商品(不能用排序) 把两步写成一步,就是子查询 from型子查询 查找出每种cat_id下goods ...
- JavaScript编程基础2
1,数据类型相关操作 使用typeof x函数查看变量的数据类型: typeof "John" // 返回 string typeof 3.14 // 返回 number type ...
- 加扰与加密&解扰与解密
原文:https://blog.csdn.net/yuan892173701/article/details/8743543 加扰就是改变标准电视信号的特性,在发送端按规定处理,而加密就是在加解扰系统 ...
- 2017-2018-2 20165221 实验三《敏捷开发与XP实践》实验报告
实验报告封面 姓名:谭笑 学号:20165221 班级:1652班 实验名称: JAVA--敏捷开发与XP实践 指导老师:娄嘉鹏 试验时间:15:35--17:15 实验性质:选修 实验组次:21 实 ...
- Http 请求头中 X-Requested-With 的含义
昨天看代码的时候,看到了这个一句 String requestedWith = ((HttpServletRequest) request).getHeader("X-Requested-W ...
- Linux 网卡驱动学习(五)(收发包具体过程)【转】
转自:https://blog.csdn.net/xy010902100449/article/details/47362787 版权声明:本文为博主原创文章,未经博主允许不得转载. https:// ...
- python骚操作之...
python中的Ellipsis对象.写作:- 中文解释:省略 该对象bool测试是为真 用途: 1.用来省略代码,作用类似于pass的一种替代方案. from collections.abc imp ...
- ES6学习笔记四(类和对象)
{ // 构造函数和实例 class Parent{ constructor(name='mukewan'){ this.name=name; } } let v_parent=new Parent( ...