CodeForces - 1325C Ehab and Path-etic MEXs

二、租用AutoDL服务器与连接教程 点击右上角控制台,选择【租用新的实例】;,我这里使用的是xshell和xftp工具(自行下载)。打开本地目录和服务器目录,直接拖动文件。 阅读详情

You are given a tree consisting of nn nodes. You want to write some labels on the tree's edges such that the following conditions hold:

  • Every label is an integer between 00 and n−2n−2 inclusive.
  • All the written labels are distinct.
  • The largest value among MEX(u,v)MEX(u,v) over all pairs of nodes (u,v)(u,v) is as small as possible.

Here, MEX(u,v)MEX(u,v) denotes the smallest non-negative integer that isn't written on any edge on the unique simple path from node uu to node vv.

Input

The first line contains the integer nn (2≤n≤1052≤n≤105) — the number of nodes in the tree.

Each of the next n−1n−1 lines contains two space-separated integers uu and vv (1≤u,v≤n1≤u,v≤n) that mean there's an edge between nodes uu and vv. It's guaranteed that the given graph is a tree.

Output

Output n−1n−1 integers. The ithith of them will be the number written on the ithith edge (in the input order).

Examples

Input

3
1 2
1 3

Output

0
1

Input

6
1 2
1 3
2 4
2 5
5 6

Output

0
3
2
4
1

Note

The tree from the second sample:

Sponsor

贪心就行 只要是叶节点就从0往后递增

不是根节点就从n-2往前递减

#include<bits/stdc++.h>
const int maxn = 1e5 + 5;
int degree[maxn];
int a[maxn];
int b[maxn];
using namespace std;
int main(){
	int n;
	cin >> n;
	for(int i = 1; i < n; i++){
		cin >> a[i] >> b[i];
		degree[a[i]]++;
		degree[b[i]]++;
	}
	int cnt = 0;
	int cnt2 = n - 2;
	for(int i = 1; i < n; i++){
		if(degree[a[i]] == 1 || degree[b[i]] == 1){
			cout << cnt << endl;
			cnt++;
		}
		else{
			cout << cnt2 << endl;
			cnt2--;
		}
	}
} 

 

西门子S7-1200PLC与FANUC机器人进行PROFINET IO通信的具体方法和步骤详解 阅读详情

相关推荐

从ADS到HFSS:耦合线带通滤波器的设计与模型转换实战

本文详细介绍了耦合线带通滤波器的完整设计流程,重点阐述了从ADS电路级快速优化到HFSS三维电磁场精确验证的模型转换实战方法。通过对比ADS理想模型仿真与HFSS全波仿真结果,指导读者进行参数校准与迭代优化,并分享了关键的板材选择、加工误差及端口设置等避坑指南,确保设计性能与实物测试高度一致。

weixin_29290863的博客 350

Codeforces 1325 C. Ehab and Path-etic MEXs(贪心构造)

题意: 给一颗树,有 nnn 个顶点,给这个树的边分别编号为 0 (n−2)0~(n-2)0 (n−2),问怎样编使得对于树上任意两点 u,vu,vu,v 的最大 mex(u,v)mex(u,v)mex(u,v) 值最小。mex(u,v)mex(u,v)mex(u,v) 表示由 uuu 到 vvv 点的简单路径的长度构成的集合中,没有出现的最小非负整数。 很简单的一个贪心策...

邵光亮的博客 14万+

三边定位的最小二乘法运用

已知:条件基站到移动台的距离D,基站的坐标(xi,yi,zi) 求:移动台的坐标(x,y,z) 运用最小二乘法的核心是找到最小二乘法的矩阵形式即 Ax=B 在本次实验中通过三边定位计算得到 A=[A;2*(xi-x1),2*(yi-y1),2*(zi-z1]; %系数矩阵A b=[b;D1^2-Di^2+xi^2+yi^2+zi^2-x1^2-y1^2-z1^2]; %增广矩阵b

qq_26250141的博客 1万+

Codeforces 1325 C. Ehab and Path-etic MEXs (思维) /详解

C. Ehab and Path-etic MEXs time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output You are given a tree consisting of n nodes. You want to write some l...

放荡者的茶会 1303

LMS Virtual.Lab二次开发:声学仿真结果导出方法(VBScript、Python)

Siemens LMS Virtual.Lab 提供一套集成软件平台用以模拟机械系统的品质属性,如结构完整性、振动噪声、耐久性、系统动力学特性、驾驶的平顺性及操纵的稳定性等。

爱看书的小沐 6036

Eclipse 数据空间组件(EDC)项目介绍

在当今数字经济的背景下,数据成为了新的“石油”。但与石油不同的是,数据可以无限共享且再生。然而,如何在保持数据主权的前提下实现高效、安全的数据共享,成为了企业和组织面临的主要挑战。这时,**Eclipse 数据空间组件(Eclipse Dataspace Components, EDC)**应运而生,它为企业在多方参与的数据交换中提供了一个标准化、可扩展的解决方案。数据空间不仅是一个多组织间的数据共享协议,还是一套支撑这些协议运行的技术基础设施。

m0_74331272的博客 4607

Codeforces C. Ehab and Path-etic MEXs (树 / 构造 / MEX)

传送门 题意: 给定一个 n 个节点 n−1 条边的树,要求给边重新标注边权,分别为 0,1,2…n-20,1,2…n−2 。然后使得树上任意两点 u,v的 MEX(u,v) 的最大值最小。 MEX(u,v) : u 到 v 的简单路径没有出现的自然数中最小的数。 思路: 当这棵树是一条链时,便可随机构造,ans(min)都是n-2。 会发现无论如何构造,边权为 0,1 的两条边总能出现在某条路径上;所以我们只需要考虑如何使得边权为 0,1,2 的三条边不同时出现在某一路径上。 因为当这棵树不为一条链时

Satur9的博客 355

Unity中使用TCP和UDP传输摄像头视频的实践

本文探讨了在Unity中通过TCP和UDP协议传输摄像头视频的实现方法。TCP通过自定义消息帧保证数据完整性但效率较低,UDP传输速度快但可能丢帧。文章提供了Python和Unity的代码示例,分析了两种协议的适用场景:TCP适合要求数据完整性的应用,UDP则适合追求实时性的场景。最终选择取决于具体需求,并需要注意线程安全与同步机制。

m0_74337424的博客 145

codeforces C. Ehab and Path-etic MEXs

题目 题意: 你有nnn个点,n−1n-1n−1条边,现在需要将max(MEX(u,v))max(MEX(u, v))max(MEX(u,v))越小越好,MEX(u,v)MEX(u, v)MEX(u,v)指的是u,vu, vu,v的唯一简单路径上的最小非负整数,比如样例中的MEX(1,5)=1,MEX(1,6)=2,MEX(2,5)=0MEX(1, 5) = 1, MEX(1,6) = 2, M...

忘梦心的博客 392

基于反事实的因果推理Causal inference based on counterfactuals--一万六千字文献详细解读(因果关系的推理应用)【全文总结】

基于反事实的因果推理Causal inference based on counterfactuals--一万六千字文献详细解读(因果关系的推理应用)【全文总结】---来自一位即将入学的准研一,也希望这篇文章能够激励自己不断走下去!!

qq_46044325的博客 4448

SAP Clean Core 对传统 ABAP 开发人员来说意味着什么:机遇和挑战

SAP Clean Core是一种战略方法,旨在优化和现代化 SAP S/4HANA 系统,通过尽量减少定制,确保核心系统的稳定性、高效性和对云环境的兼容性。Clean Core 作为一种设计思路,致力于让 ERP 系统的核心功能保持简洁、规范,避免不必要的复杂化,最终维持一个标准化的核心,使系统更容易升级、性能更优越,同时支持快速的创新能力。

2007 年 ~ 2025 年,深耕 SAP 技术 18 年 624

[codeforces 1325C] Ehab and Path-etic MEXs 绕不开的叶节点+特判

Codeforces Round #628 (Div. 2) 比赛人数9400 [codeforces 1324C] Frog Jumps 一直向右+边界处理 总目录详见https://blog.csdn.net/mrcrack/article/details/103564004 也在线测评地址https://codeforces.com/contest/1325/problem/...

mrcrack的博客 473

化工设备设计软件:PVELITE二次开发_(12).数据导入导出与兼容性

在数据导入之前,需要定义数据在PVELITE中的结构。可以通过编程接口定义字段名称和数据类型。# 导入必要的库 import pvelite # 创建PVELITE实例 pve = pvelite . PVELITE() # 定义CSV数据结构 csv_structure = {

kkchenjj的博客 1222

Codeforces 1325C. Ehab and Path-etic MEXs(构造)

Description You are given a tree consisting of n nodes. You want to write some labels on the tree’s edges such that the following conditions hold: Every label is an integer between 0 and n−2 inclusive...

名字呢? 388

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

[Codeforces Round #628]1325C - Ehab and Path-etic MEXs[思维][图]

1325C - Ehab and Path-etic MEXs[最小环] time limit per test memory limit per test input output 1 seconds 256 megabytes standard input standard output Description: You are given a tree consis...

QAQ! 的博客 253

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

CodeForces - 1325C Ehab and Path-etic MEXs(如何赋值边的权值使其满足MEX+思维)

题目链接:https://vjudge.net/contest/363511#problem/C Input 3 1 2 1 3 Output 0 1 Input 6 1 2 1 3 2 4 2 5 5 6 Output 0 3 2 4 1 翻译: 一棵树、n个点、n-1条边,构造边的值0 ~ n-2 n-1条边上的值都不相同 使得对所有u,v来说,MEX(u,v)的最大值最小。(...

zaiyang遇见 440

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

Ehab and Path-etic MEXs CodeForces - 1325C(思维+贪心)

You are given a tree consisting of n nodes. You want to write some labels on the tree’s edges such that the following conditions hold: Every label is an integer between 0 and n−2 inclusive. All the wr...

starlet_kiss的博客 504

Codeforces 1325A EhAb AnD gCd

传送门:Codeforces 1325A 要满足 GCD(a,b)+LCM(a,b)=x ,只要 a=1,b=x-1 即可。 AC代码: #include<iostream> #include<algorithm> #include<cstring> #include<cstdio> #include<cmath> #defin...

Waiting For You 501

C. Ehab and Path-etic MEXs

链接:https://codeforces.ml/contest/1325/problem/C You are given a tree consisting ofnnnodes. You want to write some labels on the tree's edges such that the following conditions hold: Every label is...

Luoriliming的博客 594

Codeforces Round #435 (Div. 2) C. Mahmoud and Ehab and the xor

Mahmoud and Ehab are on the third stage of their adventures now. As you know, Dr. Evil likes sets. This time he won't show them any set from his large collection, but will ask them to create a new set

SSimpLe_Y的博客 1346

Codeforces Round #628 (Div. 2)------Ehab and Path-etic MEXs

题目: You are given a tree consisting of n nodes. You want to write some labels on the tree’s edges such that the following conditions hold: Every label is an integer between 0 and n−2 inclusive. All th...

小` pi孩 332

Codeforces Round #628 (Div. 2)

C. Ehab and Path-etic MEXs You are given a tree consisting of n nodes. You want to write some labels on the tree’s edges such that the following conditions hold: Every label is an integer between 0 an...

TA很酷的博客 320

CodeForces - 1325D Ehab the Xorcist(构造+异或)

题目链接:点击查看 题目大意:给出一个 u 和一个 v ,要求构造出最短的一个数组,使得 所有元素异或的结果为 u 所有元素之和的结果为 v 输出构造的结果 题目分析:情况稍微比较复杂的一道构造题,读完题后,先根据样例特判,当 u 和 v 为 0 时,答案为 0 ,当 u 和 v 相等时,答案为 u,当 u > v 时,答案为 -1,这些根据样例的提示应该不难想 接下来我们应该构...

Falcon的博客 1169

Codeforces 1088E - Ehab and a component choosing problem - 贪心

Codeforces 1088E - Ehab and a component choosing problem 题解链接 https://lucien.ink 题目链接 https://codeforces.com/contest/1088/problem/E 题目 You’re given a tree consisting of nnn nodes. Every node uuu has...

LucienShui 489

[CF1039D]You Are Given a Tree[贪心+根号分治]

题意 给你\(n\)个点的树,其中一个简单路径的集合被称为\(k\)合法当且仅当树的每个节点最多属于一条路径,且每条路径包含\(k\)个节点。对于每个\(k(k \in [1,n])\),输出最多的\(k\)合法路径。 \(n\leq 10^5\)。 分析 先考虑 \(n^2\) 的做法,每次可以贪心地合并链,正确性显然。 考虑根号分治,\(k<\sqrt n\) 时 \(O(n...

aqw145212的专栏 277

Codeforces round #628 C.Ehab and Path-etic MEXs

Codeforces round #628 C.Ehab and Path-etic MEXs You are given a tree consisting of n nodes. You want to write some labels on the tree’s edges such that the following conditions hold: Every label is an...

旺崽的博客 2807
上一篇: HDU - 2476 D - String painter 区间dp
下一篇:  ZOJ - 3261 I - Connections in Galaxy War
箱@子
博客等级 码龄11年 10粉丝 130原创
评论 2
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值