1137

做过一样的 怎么又忘了 再一次搜超时

不用回溯

 #include <iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<stdlib.h>
#include<vector>
#include<queue>
using namespace std;
#define N 10010
int n,m;
vector<int>ed[N];
bool vis[N][N];
int pa[],t;
void dfs(int u)
{
int i;
for(i = ; i < (int)ed[u].size() ; i++)
{
int v = ed[u][i];
if(!vis[u][v])
{
vis[u][v] = ;
dfs(v);
}
}
t++;
pa[t] = u;
return ;
}
int main()
{
int i,j,u,v;
scanf("%d",&n);
for(i = ; i <= n ; i++)
{
scanf("%d",&m);
scanf("%d",&u);
for(j = ; j <= m ; j++)
{
scanf("%d",&v);
ed[u].push_back(v);
u = v;
}
}
dfs();
printf("%d\n",t-);
for(i = t; i > ; i--)
printf("%d ",pa[i]);
printf("%d\n",pa[]);
return ;
}

1137. Bus Routes(dfs)的更多相关文章

  1. URAL 1137 Bus Routes(欧拉回路路径)

    1137. Bus Routes Time limit: 1.0 secondMemory limit: 64 MB Several bus routes were in the city of Fi ...

  2. HDU 5552 Bus Routes(NTT+分治)

    题意 给定 \(n\) 个点,任意连边,每条边有 \(m\) 种颜色可选,求带环连通图的方案数. \(1\leq n\leq 10000\) \(1\leq m < 2^{31}\) 思路 直接 ...

  3. URAL 1137Bus Routes (dfs)

    Z - Bus Routes Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Subm ...

  4. 从壹开始微服务 [ DDD ] 之十 ║领域驱动【实战篇·中】:命令总线Bus分发(一)

    烽火 哈喽大家好,老张又见面了,这两天被各个平台的“鸡汤贴”差点乱了心神,博客园如此,简书亦如此,还好群里小伙伴及时提醒,路还很长,这些小事儿就随风而去吧,这周本不打算更了,但是被群里小伙伴“催稿”了 ...

  5. HDU ACM 1690 Bus System (SPFA)

    Bus System Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  6. 1242. Werewolf(dfs)

    1242 简单dfs 往孩子方向搜一遍 父母方向搜一遍 输入还搞什么字符串.. #include <iostream> #include<cstdio> #include< ...

  7. 1208. Legendary Teams Contest(dfs)

    1208 简单dfs 对于每个数 两种情况 取还是不取 #include <iostream> #include<cstdio> #include<cstring> ...

  8. 1124. Mosaic(dfs)

    1124 需要想那么一点点吧 一个连通块中肯定不需要伸进手不拿的情况 不是一个肯定会需要这种情况 然后注意一点 sum=0的时候 就输出0就可以了 不要再减一了 #include <iostre ...

  9. 1742. Team building(dfs)

    1742 最小的是找联通块数 最大的找环 一个环算一个 其它的数各算一个 #include <iostream> #include<cstdio> #include<cs ...

随机推荐

  1. Wijmo Angular 2 小应用

    Wijmo & Angular 2 小应用 中秋之际,Angular 团队发布 Angular 2 正式版,一款不错的图表控件Wijmo当天宣布支持 . Angular 2移除和替代了 Ang ...

  2. 【狼窝乀野狼】Excel那些事儿

    在工作中我们常常遇到Excel表格,不管是数据的导入导出,还是财务统计什么都,都离不开Excel,Excel是我见过的最牛逼的一个软件(可能我的见识少)没有之一:如果你只停留在Excel处理数据,统计 ...

  3. TypeError: Object #<IncomingMessage> has no method 'flash'

    JavaScript相关代码: router.post('/reg', function(req, res) { //检验用户两次输入的口令是否一致 if (req.body['password-re ...

  4. ffmpeg 错误码

    av_read_frame, av_write_frame等 经常会返回负值也即写数据包失败.不同的负值代表不同的含义,可以根据错误码定义,定位问题. #define EPERM 1 /* Opera ...

  5. [原创] zabbix学习之旅七:如何远程操作被监控机器

    虽然我们已经创建了一个报警系统,但在实际场景中,运维人员从得到报警到实际解决问题有一定的时差,若业务系统没有做高可用,那业务不得不中断,对于某些要求严格的企业级环境,这是不可容忍的,那有没有方法能让z ...

  6. C#WinForm中播放背景音乐(亲测可用)

    using System.Runtime.InteropServices; public static uint SND_ASYNC = 0x0001; public static uint SND_ ...

  7. input框中value与placeholder的区别

    value:是input中预先放置的文字,当鼠标点击之后依然存在,是值的一部分. placeholder:是input中输入位置的默认显示的文字,鼠标点击后仍旧显示,但不属于值,类似于背景.

  8. 【环境】Linux下连接无线网常用命令

    启用/重启/关闭 网络服务 /etc/init.d/networking start /etc/init.d/networking restart /etc/init.d/networking sto ...

  9. nenu contest3

    http://vjudge.net/contest/view.action?cid=55702#overview 12656 - Almost Palindrome http://uva.online ...

  10. [转载]C#获取进程的主窗口句柄

    public class User32API { private static Hashtable processWnd = null; public delegate bool WNDENUMPRO ...