D. Innokenty and a Football League

Innokenty is a president of a new football league in Byteland. The first task he should do is to assign short names to all clubs to be shown on TV next to the score. Of course, the short names should be distinct, and Innokenty wants that all short names consist of three letters.

Each club‘s full name consist of two words: the team‘s name and the hometown‘s name, for example, "DINAMO BYTECITY". Innokenty doesn‘t want to assign strange short names, so he wants to choose such short names for each club that:

  1. the short name is the same as three first letters of the team‘s name, for example, for the mentioned club it is "DIN",
  2. or, the first two letters of the short name should be the same as the first two letters of the team‘s name, while the third letter is the same as the first letter in the hometown‘s name. For the mentioned club it is "DIB".

Apart from this, there is a rule that if for some club x the second option of short name is chosen, then there should be no club, for which the first option is chosen which is the same as the first option for the club x. For example, if the above mentioned club has short name "DIB", then no club for which the first option is chosen can have short name equal to "DIN". However, it is possible that some club have short name "DIN", where "DI" are the first two letters of the team‘s name, and "N" is the first letter of hometown‘s name. Of course, no two teams can have the same short name.

Help Innokenty to choose a short name for each of the teams. If this is impossible, report that. If there are multiple answer, any of them will suit Innokenty. If for some team the two options of short name are equal, then Innokenty will formally think that only one of these options is chosen.

Input

The first line contains a single integer n (1?≤?n?≤?1000) — the number of clubs in the league.

Each of the next n lines contains two words — the team‘s name and the hometown‘s name for some club. Both team‘s name and hometown‘s name consist of uppercase English letters and have length at least 3 and at most 20.

Output

It it is not possible to choose short names and satisfy all constraints, print a single line "NO".

Otherwise, in the first line print "YES". Then print n lines, in each line print the chosen short name for the corresponding club. Print the clubs in the same order as they appeared in input.

If there are multiple answers, print any of them.

然后这个问题要是转化为图形语言的话,感觉这个问题就是很容易的解决了,所以我现在画个图。

每个club能选择两个名字,保证选的n个名字不会相同,并且要是选择x2,如果y1==x1就不能选择y1,同理。。。

这就是大致的题意,如果我把题目画成这个图,感觉题目就能很容易的解决出来了,所以基本的思路就是2-sat.然后把路径输出就行了。

定义两个状态要是选择第一个名字定义为1,否则的话就是定义为0。所以我们现在要做的就是for循环枚举每一个状态,然后就是套用模板就行了。

时间: 2024-10-13 16:17:54

D. Innokenty and a Football League的相关文章

Codeforces Round #403 D. Innokenty and a Football League

题目链接:Codeforces Round #403 D. Innokenty and a Football League 题意: 某人需要给若干球队选择队名缩写.已知每个球队的名字必然是 <team name> <hometown name> 的形式.取队名缩写的规则是固定的,只有两种: 选择 team name 的前三个字母作为队名缩写 选择 team name 的前两个字母与 hometown name 的首字母组成队名缩写. 每个队的队名缩写都可以从两种中任选一种,问能够使

Codeforces Round #403 (Div. 1, based on Technocup 2017 Finals)

Div1单场我从来就没上过分,这场又剧毒,半天才打出B,C挂了好几次最后还FST了,回紫了. AC:AB Rank:340 Rating:2204-71->2133 Div2.B.The Meeting Place Cannot Be Changed 题目大意:n个人,第i个人位于xi,速度为vi,找到一个点使得所有人到这个点的耗时最小,输出耗时.(n<=60000) 思路:二分答案,知道耗时后可以求出每个人能到达的区间,如果所有区间有交则合法,复杂度O(nlog). #include<

老男孩猛龙过江抢先看 走起

小萌库 一周电影秀  [大陆喜剧]老男孩猛龙过江<老男孩猛龙过江>是从李小龙原创电影<猛龙过江>来的灵感,筷子兄弟武戏部分灵感来自李小龙,是一部致敬李小龙的喜剧动作电影,由肖央编剧.执导,香港知名导演李仁港监制,“筷子兄弟”[4] 肖央.王太利联手出演. 电影在浓厚的喜剧氛围下,讲述了两个怀揣梦想的大叔孤注一掷跨国寻梦的冒险历程.片中郁郁不得志的“筷子兄弟”将迎来事业的“第二春”,在大洋彼岸上演了一系列的爆笑励志闹剧. 2014年1月9日,“老男孩纽约归来”的发布会在京举办,肖央.

6940

Some work gloves are better suitable certain types of riding than others On time your significant other to take a healthy interest in the hand by putting your signature on her way up for a golf pool It is really Authentic National football league jer

医学领域一些较新的词汇中英文对照

AARP [=American Association of Retired Persons]美国退休者协会 abscesses 脓肿 abstinence 戒酒 acetylcholine 乙酰胆碱 acrylamide 丙烯酰胺 Acting Deputy Commissioner for Policy 政策代理副专员 actinic keratosis 光化性角化病 activity 活度 acylcarnitines 酰基肉毒碱 adhesive pads 粘性衬垫 Administra

解题报告 之 WHU1124 Football Coach

解题报告 之 WHU1124 Football Coach Description It is not an easy job to be a coach of a football team. The season is almost over, only a few matches are left to play. All of sudden the team manager comes to you and tells you bad news: the main sponsor of

Codeforces Round #281 (Div. 2) A. Vasya and Football 暴力

A. Vasya and Football Vasya has started watching football games. He has learned that for some fouls the players receive yellow cards, and for some fouls they receive red cards. A player who receives the second yellow card automatically receives a red

POJ 3071 Football

Description Consider a single-elimination football tournament involving 2n teams, denoted 1, 2, -, 2n. In each round of the tournament, all teams still in the tournament are placed in a list in order of increasing index. Then, the first team in the l

CodeForces 432B Football Kit(水)

Description Consider a football tournament where n teams participate. Each team has two football kits: for home games, and for away games. The kit for home games of the i-th team has color xi and the kit for away games of this team has color yi(xi ≠