A1394 | [COCI-2020-2021-contest6]#1 Alias
来源COCI
时间限制1s
内存限制128MB
通过 / 提交0/0
题目描述
Novak and Rafael are playing a simplified version of the game Alias. Novak needs to make Rafael guess a word without saying it. Rafael has a database of n words in his head, and there are m connections between some words. The connection between words x and y, with time t, means that if Rafael remembers the word x or hears it, after t milliseconds he will remember the word y.
Novak and Rafael will play q rounds. In each round, Novak wants to know: if he says the word a, after how many milliseconds will Rafael remember the word b for the first time? The rounds are independent.
Novak and Rafael will play q rounds. In each round, Novak wants to know: if he says the word a, after how many milliseconds will Rafael remember the word b for the first time? The rounds are independent.
输入格式
The first line contains integers n (2 ≤ n ≤ 1000) and m (1 ≤ m ≤ 1000), the number of words and the number of connections.
Each of the following m lines contains two different words xi and yi , and an integer ti (1 ≤ ti ≤ 109 ), that describe a connection. The words consist of at most 20 lowercase letters. All words from Rafael’s database will appear at least once. It is possible that there are multiple connections between some pairs of words.
The following line contains an integer q (1 ≤ q ≤ 1000), the number of rounds.
Each of the following q lines contains two different words ai and bi , the word that Novak will say and the word that Rafael needs to remember in the i-th round. Both words appear in Rafael’s database.
Each of the following m lines contains two different words xi and yi , and an integer ti (1 ≤ ti ≤ 109 ), that describe a connection. The words consist of at most 20 lowercase letters. All words from Rafael’s database will appear at least once. It is possible that there are multiple connections between some pairs of words.
The following line contains an integer q (1 ≤ q ≤ 1000), the number of rounds.
Each of the following q lines contains two different words ai and bi , the word that Novak will say and the word that Rafael needs to remember in the i-th round. Both words appear in Rafael’s database.
输出格式
Output q lines. In the i-th line output the time for the i-th round in milliseconds, or Roger if Rafael will never remember the word.
输入输出样例
输入 #1
3 2 novak goat 1 goat simulator 3 2 novak simulator simulator goat
输出 #1
4 Roger
输入 #2
3 3 kile legend 4 legend beer 5 beer kile 6 2 kile beer legend kile
输出 #2
9 11
In test cases worth 20 points, it holds 1 ≤ n ≤ 10.
In test cases worth additional 20 points, it holds 1 ≤ n ≤ 100.
Clarification of the first example:
In the first round, Novak will say the word novak. After 1 millisecond, Rafael will remember the word
goat, and after 3 more milliseconds the required word simulator. In the second round, Novak will say
the word simulator, but Rafael won’t remember any other words.
In test cases worth additional 20 points, it holds 1 ≤ n ≤ 100.
Clarification of the first example:
In the first round, Novak will say the word novak. After 1 millisecond, Rafael will remember the word
goat, and after 3 more milliseconds the required word simulator. In the second round, Novak will say
the word simulator, but Rafael won’t remember any other words.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted