ICPCCamp 2016 Day1 ftiasch's Contest #4(Around the world-树,构造)
来源:互联网 发布:错别字检测软件 编辑:程序博客网 时间:2024/06/09 23:43
已知一个有n个点(4<=n<=500)连通无向图,边权均为1。点的编号为
v1,v2,...,vn 是不同的点- 对
2≤i≤n ,有dis(vi,vi+1)≤k<n (k是给定的常数)
题解:考虑一棵树,从1号节点出发按dfs序走一遍,下去时走
#include<cstdio>#include<cstring>#include<cstdlib>#include<algorithm>#include<functional>#include<iostream>#include<cmath>#include<cctype>#include<ctime>#include<iomanip> using namespace std;#define For(i,n) for(int i=1;i<=n;i++)#define Fork(i,k,n) for(int i=k;i<=n;i++)#define Rep(i,n) for(int i=0;i<n;i++)#define ForD(i,n) for(int i=n;i;i--)#define RepD(i,n) for(int i=n;i>=0;i--)#define Forp(x) for(int p=pre[x];p;p=next[p])#define Forpiter(x) for(int &p=iter[x];p;p=next[p]) #define Lson (x<<1)#define Rson ((x<<1)+1)#define MEM(a) memset(a,0,sizeof(a));#define MEMI(a) memset(a,127,sizeof(a));#define MEMi(a) memset(a,128,sizeof(a));#define INF (2139062143)#define F (100000007)#define pb push_back#define mp make_pair#define fi first#define se second#define vi vector<int> typedef long long ll;ll mul(ll a,ll b){return (a*b)%F;}ll add(ll a,ll b){return (a+b)%F;}ll sub(ll a,ll b){return (a-b+llabs(a-b)/F*F+F)%F;}void upd(ll &a,ll b){a=(a%F+b%F)%F;}int read(){ int x=0,f=1; char ch=getchar(); while(!isdigit(ch)) {if (ch=='-') f=-1; ch=getchar();} while(isdigit(ch)) { x=x*10+ch-'0'; ch=getchar();} return x*f;} #define MAXN (500+10)int n,k;char s[MAXN];int f[MAXN][MAXN]={0};bool vis[MAXN]={0};void dfs(int x,int l){ vis[x]=1; if (!l) { if (x>1) cout<<" "; cout<<x; } For(i,n) if (!vis[i]&&f[x][i]) { dfs(i,l^1); } if (l) cout<<' '<<x;}int main(){// freopen("D.in","r",stdin);// freopen(".out","w",stdout); n=read(),k=read(); For(i,n) { cin>>(s+1); For(j,n) if (s[j]=='1') f[i][j]=1; } dfs(1,0); cout<<endl; return 0;}
0 0
- ICPCCamp 2016 Day1 ftiasch's Contest #4(Around the world-树,构造)
- ICPCCamp 2016 Day1 ftiasch's Contest #4(All Pair Shortest Path-位运算)
- ICPCCamp 2016 Day 8 - Makoto Soejima's Contest #4(Ropes-树的度数与方案数)
- ICPCCamp 2016 Day 8 - Makoto Soejima's Contest #4(String Modification-模拟)
- ICPCCamp 2016 Day 4 - SJTU Dreadnought Contest(The Road Network-区间dp)
- 2016 四川省赛 Around the World
- bzoj3827:[Poi2014]Around the world
- BZOJ3827[Poi2014] Around the world
- BZOJ3827: [Poi2014]Around the world
- IcpcCamp-day1-E
- poj 2432 Around the world bfs+哈希
- bnuoj 52305 Around the World dfs+排列组合
- CHILDBIRTH TRADITIONS AROUND THE WORLD: CHINA
- hdu contest day1 1001 OO’s Sequence
- 2016年四川省赛H题 Around the World(BEST定理||树形dp)
- ICPCCamp Day1 C. City United(脑洞状压dp)
- Ganymede Around the world中我的名字
- Around the World in Eighty Days 5/201
- linux文件I/O
- Android客户端与服务器端交互数据之json解析
- JAVA中的包装类
- 最大子矩阵和(dp)
- addr2line 工具
- ICPCCamp 2016 Day1 ftiasch's Contest #4(Around the world-树,构造)
- 算法导论例程——最大子数组问题
- 由面向对象的思想走进java单例模式
- 例题10-24 UVA 1641 ASCII Area(ASCII面积)
- UVALive 3634 熟悉一下STL
- 第七章 跨内容共享数据,探究内容提供器
- 项目结构
- 解决Xcode Code Signing Identity不可以选择
- Oracle11g系统账号密码忘记解决办法