A. Neverending competitions

Codeforces
IDCF765A
Time2000ms
Memory512MB
Difficulty
implementationmath
English · Original
Chinese · Translation
Formal · Original
There are literally dozens of snooker competitions held each year, and team Jinotega tries to attend them all (for some reason they prefer name "snookah")! When a competition takes place somewhere far from their hometown, Ivan, Artsem and Konstantin take a flight to the contest and back. Jinotega's best friends, team Base have found a list of their itinerary receipts with information about departure and arrival airports. Now they wonder, where is Jinotega now: at home or at some competition far away? They know that: * this list contains all Jinotega's flights in this year (**in arbitrary order**), * Jinotega has only flown from his hometown to a snooker contest and back, * after each competition Jinotega flies back home (though they may attend a competition in one place several times), * and finally, at the beginning of the year Jinotega was at home. Please help them to determine Jinotega's location! ## Input In the first line of input there is a single integer _n_: the number of Jinotega's flights (1 ≤ _n_ ≤ 100). In the second line there is a string of 3 capital Latin letters: the name of Jinotega's home airport. In the next _n_ lines there is flight information, one flight per line, in form "_XXX->YYY_", where "_XXX_" is the name of departure airport "_YYY_" is the name of arrival airport. Exactly one of these airports is Jinotega's home airport. It is guaranteed that flights information is consistent with the knowledge of Jinotega's friends, which is described in the main part of the statement. ## Output If Jinotega is now at home, print "_home_" (without quotes), otherwise print "_contest_". [samples] ## Note In the first sample Jinotega might first fly from SVO to CDG and back, and then from SVO to LHR and back, so now they should be at home. In the second sample Jinotega must now be at RAP because a flight from RAP back to SVO is not on the list.
每年有数十场斯诺克比赛举行,Jinotega 队试图参加所有比赛(因为他们更喜欢称之为“snookah”)!当比赛在远离他们家乡的地方举行时,Ivan、Artsem 和 Konstantin 会乘飞机前往比赛地点并返回。 Jinotega 的好朋友 Base 队找到了一份他们的行程收据列表,其中包含出发和到达机场的信息。现在他们想知道:Jinotega 现在是在家,还是在某个遥远的比赛地点?他们知道: 请帮助他们确定 Jinotega 的位置! 输入的第一行包含一个整数 #cf_span[n]:Jinotega 的航班数量(#cf_span[1 ≤ n ≤ 100])。第二行是一个由 #cf_span[3] 个大写拉丁字母组成的字符串:Jinotega 家乡机场的名称。接下来的 #cf_span[n] 行每行包含一条航班信息,格式为 "_XXX->YYY_",其中 "_XXX_" 是出发机场名称,"_YYY_" 是到达机场名称。这些机场中恰好有一个是 Jinotega 的家乡机场。 保证航班信息与主陈述中描述的 Jinotega 朋友所掌握的信息一致。 如果 Jinotega 现在在家,请输出 "_home_"(不含引号),否则输出 "_contest_"。 在第一个样例中,Jinotega 可能先从 SVO 飞往 CDG 再返回,然后从 SVO 飞往 LHR 再返回,因此他们现在应在家中。在第二个样例中,Jinotega 现在一定在 RAP,因为从 RAP 返回 SVO 的航班未出现在列表中。 ## Input 输入的第一行包含一个整数 #cf_span[n]:Jinotega 的航班数量(#cf_span[1 ≤ n ≤ 100])。第二行是一个由 #cf_span[3] 个大写拉丁字母组成的字符串:Jinotega 家乡机场的名称。接下来的 #cf_span[n] 行每行包含一条航班信息,格式为 "_XXX->YYY_",其中 "_XXX_" 是出发机场名称,"_YYY_" 是到达机场名称。这些机场中恰好有一个是 Jinotega 的家乡机场。保证航班信息与主陈述中描述的 Jinotega 朋友所掌握的信息一致。 ## Output 如果 Jinotega 现在在家,请输出 "_home_"(不含引号),否则输出 "_contest_"。 [samples] ## Note 在第一个样例中,Jinotega 可能先从 SVO 飞往 CDG 再返回,然后从 SVO 飞往 LHR 再返回,因此他们现在应在家中。在第二个样例中,Jinotega 现在一定在 RAP,因为从 RAP 返回 SVO 的航班未出现在列表中。
Given: - $ n $: number of flights, $ 1 \leq n \leq 100 $ - $ H $: home airport (string of 3 capital letters) - $ n $ flight segments, each of the form $ A \to B $, where exactly one of $ A $ or $ B $ is $ H $ Each flight is a round trip: for every departure from $ H $ to $ X $, there must be a return from $ X $ to $ H $, unless the trip is incomplete. Let $ F $ be the multiset of flights $ \{(A_i, B_i)\}_{i=1}^n $. Define: - $ \text{out}_H $: number of flights departing from $ H $ - $ \text{in}_H $: number of flights arriving at $ H $ Since each complete round trip contributes one departure and one arrival at $ H $, the net displacement from home is determined by the imbalance: If $ \text{out}_H = \text{in}_H $, then Jinotega is at home. If $ \text{out}_H > \text{in}_H $, then Jinotega is at a contest (unreturned from last flight). Because each flight has exactly one endpoint at $ H $, every flight is either $ H \to X $ or $ X \to H $, so: $$ \text{out}_H + \text{in}_H = n $$ And the current location is: - **home** if $ \text{out}_H = \text{in}_H $ - **contest** if $ \text{out}_H \neq \text{in}_H $ But since $ \text{out}_H + \text{in}_H = n $, then $ \text{out}_H = \text{in}_H $ iff $ n $ is even. Alternatively, since each complete round trip uses two flights (out and back), an odd number of flights implies an incomplete trip — so Jinotega is away. Thus: $$ \text{location} = \begin{cases} \text{home} & \text{if } n \text{ is even} \\ \text{contest} & \text{if } n \text{ is odd} \end{cases} $$ **Note**: The guarantee that flights are consistent and each has exactly one endpoint at $ H $ ensures this parity condition is sufficient. --- **Formal Output Rule**: If $ n \mod 2 = 0 $, output `"home"` Else, output `"contest"`
Samples
Input #1
4
SVO
SVO->CDG
LHR->SVO
SVO->LHR
CDG->SVO
Output #1
home
Input #2
3
SVO
SVO->HKT
HKT->SVO
SVO->RAP
Output #2
contest
API Response (JSON)
{
  "problem": {
    "name": "A. Neverending competitions",
    "description": {
      "content": "There are literally dozens of snooker competitions held each year, and team Jinotega tries to attend them all (for some reason they prefer name \"snookah\")! When a competition takes place somewhere far",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 524288
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF765A"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "There are literally dozens of snooker competitions held each year, and team Jinotega tries to attend them all (for some reason they prefer name \"snookah\")! When a competition takes place somewhere far...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "每年有数十场斯诺克比赛举行,Jinotega 队试图参加所有比赛(因为他们更喜欢称之为“snookah”)!当比赛在远离他们家乡的地方举行时,Ivan、Artsem 和 Konstantin 会乘飞机前往比赛地点并返回。\n\nJinotega 的好朋友 Base 队找到了一份他们的行程收据列表,其中包含出发和到达机场的信息。现在他们想知道:Jinotega 现在是在家,还是在某个遥远的比赛地点?他们...",
      "is_translate": true,
      "language": "Chinese"
    },
    {
      "statement_type": "Markdown",
      "content": "Given:\n- $ n $: number of flights, $ 1 \\leq n \\leq 100 $\n- $ H $: home airport (string of 3 capital letters)\n- $ n $ flight segments, each of the form $ A \\to B $, where exactly one of $ A $ or $ B $ ...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments