暴力删边,暴力枚举

#include <bits/stdc++.h>

using namespace std;

#define MAXM 5010

inline int read()
{
int x = ,ff = ;char ch = getchar();
while(!isdigit(ch))
{
if(ch == '-') ff = -;
ch = getchar();
}
while(isdigit(ch))
{
x = (x << ) + (x << ) + (ch ^ );
ch = getchar();
}
return x * ff;
} inline void write(int x)
{
if(x < ) putchar('-'),x = -x;
if(x > ) write(x / );
putchar(x % + '');
} int a,b,x,y,dx,dy,top = ,c[MAXM],vis[MAXM],T[MAXM],m[MAXM],e[MAXM][];
vector < int > q[MAXM]; inline void dfs(int x)
{ T[++top] = x; vis[x] = true;
int l = q[x].size();
for(int i = ;i < l;++i)
{
int y = q[x][i];
if((vis[y]) || (x == dx && y == dy) || (x == dy && y == dx)) continue;
dfs(y);
}
return ;
} inline void check()
{
for(int i = ;i <= a;++i)
{
if(m[i] != T[i])
{
if(m[i] < T[i]) return ;
break;
}
}
for(int i = ;i <= a;++i)
m[i] = T[i];
} int main()
{
memset(m,0x3f,sizeof(m));
a = read(); b = read();
for(int i = ;i <= b;++i)
{
int x,y;
x = read(); y = read();
q[x].push_back(y);
q[y].push_back(x);
e[i][] = x;
e[i][] = y;
}
for(int i = ;i <= a;++i)
sort(q[i].begin(),q[i].end());
if(b == a - )
{
dx = -; dy = -;
dfs();
for(int i = ;i <= a;++i)
write(T[i]),putchar(' ');
}
else
{
for(int i = ;i <= b;++i)
{
top = ;
dx = e[i][];
dy = e[i][];
memset(T,,sizeof(T));
memset(vis,false,sizeof(vis));
dfs();
if(top != a) continue;
check();
}
for(int i = ;i <= a;++i)
write(m[i]),putchar(' ');
}
return ;
}

noip 2018 Day2 T1 旅行的更多相关文章

  1. noip 2018 day2 T1 旅行 基环树 tarjan

    Code: #include<cstdio> #include<cstring> #include<string> #include<stack> #i ...

  2. 3730 无线网络发射选址[NOIP 0214 day2 T1]

    3730 无线网络发射选址  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 青铜 Bronze 题解  查看运行结果     题目描述 Description 随着智能手机的日 ...

  3. NOIP 2014 Day2 T1 无线网络发射器

    #include<iostream> #include<cmath> #include<cstdlib> #include<cstdio> #inclu ...

  4. noip 2016 day2 t1组合数问题

    题目描述 组合数表示的是从n个物品中选出m个物品的方案数.举个例子,从(1,2,3) 三个物品中选择两个物品可以有(1,2),(1,3),(2,3)这三种选择方法.根据组合数的定 义,我们可以给出计算 ...

  5. Codevs 3578 无线网络发射器选址== NOIP 2014 Day2 T1

    3578 无线网络发射器选址 时间限制: 1 s 空间限制: 64000 KB 题目等级 : 白银 Silver 题目描述 Description 随着智能手机的日益普及,人们对无线网的需求日益增大. ...

  6. noip 2018 day1 T1 铺设道路 贪心

    Code: #include<cstdio> using namespace std; int main() { int last=0,ans=0; int n;scanf("% ...

  7. [NOIp 2018]all

    Description 题库链接: Day1 T1 铺设道路 Day1 T2 货币系统 Day1 T3 赛道修建 Day2 T1 旅行 Day2 T2 填数游戏 Day2 T3 保卫王国 Soluti ...

  8. noip 2018 d2t1 旅行

    noip 2018 d2t1 旅行 (题目来自洛谷) 给定n个城市,m条双向道路的图, 不存在两条连接同一对城市的道路,也不存在一条连接一个城市和它本身的道路.并且, 从任意一个城市出发,通过这些道路 ...

  9. NOIP 2018 总结

    NOIP 2018 总结 提高组: 应得分 \(100 + 100 + 40 + 100 + 50 + 44 = 434\). 考后期望得分 \(100 + 100 + 20 + 100 + 50 + ...

随机推荐

  1. 【iOS】KVC 与 KVO

    一.KVC与KVO *"KVC":key value Coding(键值编码) *目的:间接的改动或获取对象的属性,减少程序(类与类)之间的耦合度. *"KVO" ...

  2. Javascript中没有引用传递,只有按值传递

    很多人,包括我,受书本知识消化不彻底的影响,认为 JS 中参数有两种传递方式:数字.字符串等按值传递:数组.对象等按地址(引用)传递.对此种观点,我们要谨慎. var v1 = [] var v2 = ...

  3. c++string 输入换行符

    string 一次只能输入一行,不含换行符.可以自己添加换行符 和输入行数.例如:#include <iostream>#include <string>using names ...

  4. querying rpm database

    Call dbMatch on a transaction set to create a match iterator. As with the C API, a match iterator al ...

  5. <转载>调制与解调电路详解

    原文链接:http://www.elecfans.com/analog/20120509270848_4.html 调幅和检波电路 广播和无线电通信是利用调制技术把低频声音信号加到高频信号上发射出去的 ...

  6. HDU 6119 小小粉丝度度熊 【预处理+尺取法】(2017"百度之星"程序设计大赛 - 初赛(B))

    小小粉丝度度熊 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Sub ...

  7. 分析PHP的include机制

    php在解析include指令时,会对包含的文件路径做如下判断: 如果是绝对路径,则直接包含,并结束. 如果是相对路径,则做如下判断: 相对路径以特殊符号开头,如 "./1.php" ...

  8. 如何用redis做到限制,一个手机号,1分钟内最多发一条,一天内最多10条

    需要两个缓存 key名称 phone-busy,缓存1分钟 key名称 phone-send-count,缓存1天,每成功发送一条+1 发送的时候流程如下: 判断phone-busy是否存在,存在直接 ...

  9. get all sites under IIS

    https://stackoverflow.com/questions/2555668/how-to-programmatically-get-sites-list-and-virtual-dirs- ...

  10. MYSQL进阶学习笔记二:MySQL存储过程和局部变量!(视频序号:进阶_4-6)

    知识点三:MySQL存储过程和局部变量(4,5,6) 存储过程的创建:     创建存储过程的步骤: 首先选中数据库 改变分隔符,不让分号作为执行结束的标记.(通常情况下,改变分隔符命令 DELIMI ...