【Atcoder】 日本最強プログラマー学生選手権-予選-D(dfs染色结合无判断二分规律)

Problem Statement

AtCoder's head office consists of NN rooms numbered 11 to NN. For any two rooms, there is a direct passage connecting these rooms.

For security reasons, Takahashi the president asked you to set a level for every passage, which is a positive integer and must satisfy the following condition:

  • For each room i (1≤i≤N)i (1≤i≤N), if we leave Room ii, pass through some passages whose levels are all equal and get back to Room ii, the number of times we pass through a passage is always even.

Your task is to set levels to the passages so that the highest level of a passage is minimized.

Constraints

  • NN is an integer between 22 and 500500 (inclusive).

Input

Input is given from Standard Input in the following format:

N

Output

Print one way to set levels to the passages so that the objective is achieved, as follows:

a1,2a1,2 a1,3a1,3 ...... a1,Na1,N
a2,3a2,3 ...... a2,Na2,N
..
..
..
aN−1,NaN−1,N

Here ai,jai,j is the level of the passage connecting Room ii and Room jj.

If there are multiple solutions, any of them will be accepted.


Sample Input 1 Copy

Copy

3

Sample Output 1 Copy

Copy

1 2
1

The following image describes this output:

【Atcoder】 日本最強プログラマー学生選手権-予選-D(dfs染色结合无判断二分规律)_第1张图片

 

For example, if we leave Room 22, traverse the path 2→3→2→3→2→1→22→3→2→3→2→1→2 while only passing passages of level 11 and get back to Room 22, we pass through a passage six times.

题意:

从一个点出发经过一些走廊再回来,经过的走廊数量必须是偶数,走廊的等级(题目要求的)必须一样

输出两两之间走廊的等级

有点类似二分图。通过拿点分成两份将路线分解成两份

证明有些困难。不过看一些样例,猜测一下也是可以的

#include
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define niv vector
#define LL long long
#define IT iterator
#define PB(a) push_back(a)
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a mp;
typedef pair superpair;
int  n;
int res[505][505];
void dfs(int start,int to,int index){
	if(to-start+1<=1) return;
	for(int i=start;i>1;
	dfs(start,mid,index+1),dfs(mid+1,to,index+1);
}
int main(){
	cin>>n;
	dfs(1,n,1);

	for(int i=1;i

 

 

 

 

你可能感兴趣的:(DFS,Atcoder)