C - Simple path

C - Simple path

Time Limit: 2 sec / Memory Limit: 1024 MB

Score : 300300 points

Problem Statement

There is a tree TT with NN vertices. The ii-th edge (1\leq i\leq N-1)(1≤i≤N−1) connects vertex U_iUi​ and vertex V_iVi​.

You are given two different vertices XX and YY in TT. List all vertices along the simple path from vertex XX to vertex YY in order, including endpoints.

It can be proved that, for any two different vertices aa and bb in a tree, there is a unique simple path from aa to bb.

What is a simple path?

Constraints

  • 1\leq N\leq 2\times 10^51≤N≤2×105
  • 1\leq X,Y\leq N1≤X,Y≤N
  • X\neq YX=Y
  • 1\leq U_i,V_i\leq N1≤Ui​,Vi​≤N
  • All values in the input are integers.
  • The given graph is a tree.

Input

The input is given from Standard Input in the following format:

NN XX YY
U_1U1​ V_1V1​
U_2U2​ V_2V2​
\vdots⋮
U_{N-1}UN−1​ V_{N-1}VN−1​

Output

Print the indices of all vertices along the simple path from vertex XX to vertex YY in order, with spaces in between.


Sample Input 1 Copy

Copy

5 2 5
1 2
1 3
3 4
3 5

Sample Output 1 Copy

Copy

2 1 3 5

The tree TT is shown below. The simple path from vertex 22 to vertex 55 is 22 \to→ 11 \to→ 33 \to→ 55.
Thus, 2,1,3,52,1,3,5 should be printed in this order, with spaces in between.


Sample Input 2 Copy

Copy

6 1 2
3 1
2 5
1 2
4 1
2 6

Sample Output 2 Copy

Copy

1 2

The tree TT is shown below.

#include <iostream>
#include <vector>
#include <cstring>
using namespace std;
const int N=200005;
struct e
{
	vector<int> vt;
} eg[N];

int n,x,y,sum=1;
bool vis[N];
int ans[N];
void dfs(int u)
{
	int res=1;
	ans[sum]=u;
	if(u==y)
	{
		for(int i=1;i<=sum;i++)
		{
			cout<<ans[i]<<" ";
		}
		return;
	}
	for(vector<int>::iterator it=eg[u].vt.begin();it!=eg[u].vt.end();it++)
	{
		int v=*it;
		if(!vis[v])
		{
			sum+=res;
			vis[v]=true;
			dfs(v);
			vis[v]=false;
			sum--;
		}
	}
	return;
}

int main() 
{
	memset(vis,false,sizeof(vis));
	int u,v;
	cin>>n>>x>>y;
	n--;
	while(n--)
	{
		cin>>u>>v;
		eg[u].vt.push_back(v);
		eg[v].vt.push_back(u);
	}
	vis[x]=true;
	dfs(x);
	return 0;
}

运行 `weston-simple-recorder -h` 命令可以显示 `weston-simple-recorder` 工具的帮助信息,如下所示: ``` Usage: weston-simple-recorder [OPTIONS...] -h, --help display this help text and exit -o, --output FILE specify the output file name and path -f, --output-format FORMAT specify the output file format (webm,mp4) -c, --codec CODEC specify the video codec -s, --scale SCALE specify the output file scaling factor -r, --framerate RATE specify the output file framerate -q, --quality QUALITY specify the output file quality -x, --x POSITION specify the x-coordinate of the capture area -y, --y POSITION specify the y-coordinate of the capture area -w, --width PIXELS specify the width (in pixels) of the capture area -h, --height PIXELS specify the height (in pixels) of the capture area -i, --idle-timeout SECONDS specify the idle timeout in seconds -b, --background run in the background -v, --verbose enable verbose logging ``` 可以看到,`weston-simple-recorder` 工具支持多个命令行选项,包括: - `-o/--output`:指定输出文件的路径和名称; - `-f/--output-format`:指定输出文件的格式,支持 WebM 和 MP4 两种格式; - `-c/--codec`:指定视频编码器; - `-s/--scale`:指定输出文件的缩放比例; - `-r/--framerate`:指定输出文件的帧率; - `-q/--quality`:指定输出文件的质量; - `-x/--x`:指定要录制的区域的左上角 x 坐标; - `-y/--y`:指定要录制的区域的左上角 y 坐标; - `-w/--width`:指定要录制的区域的宽度; - `-h/--height`:指定要录制的区域的高度; - `-i/--idle-timeout`:指定空闲超时时间,即在无操作状态下,自动停止录制的时间; - `-b/--background`:在后台运行; - `-v/--verbose`:启用详细日志记录。 使用时可以根据需要设置相应的选项。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

linalw

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值