码迷,mamicode.com
首页 > 其他好文 > 详细

I love Codeforces

时间:2018-08-05 22:35:18      阅读:239      评论:0      收藏:0      [点我收藏+]

标签:fir   admin   ext   evel   anon   can   any   contest   inf   

I love Codeforces
time limit per test
2.0 s
memory limit per test
256 MB
input
standard input
output
standard output

Among participants of programming contests at codeforces.com the following tradition is common: whenever a participant falls in love with another participant, he changes his nickname to ?I_love_<nickname of the participant he fell in love with>?. Unfortunately, for technical reasons site administration has lost the current nicknames of participants who had changed their nicknames recently, but the information about who of them fell in love with whom remains. Now the administration needs to write a program for determining the current nickname of the given participant. It should be noted that due to the small bug in the database structure different participants can have the same nicknames on this site.

Input

The first line contains a single integer n (2?≤?n?≤?200000) — the number of participants.

In the next n lines initial nicknames of participants are given. Each nickname is a non-empty string of length at most 24 characters, consisting only of uppercase and lowercase Latin letters and also underscores. Some nicknames can coincide.

The next line contains a single integer m (1?≤?m?≤?200000) — the number of records that one of the participants fell in love with another participant.

In the next m lines pairs of integers aj and bj, separated by a space, are given (1?≤?aj,?bj?≤?naj?≠?bj) — a record that the aj-th participant fell in love with the bj-th participant and changed his nickname correspondingly. Participants are numbered from one in the order their initial nicknames are given. Renamings occur in the order they are given.

Output

In the only line output the final nickname of the first participant after all renamings.

Examples
input
Copy
5
anonymous
natalia
LeBron
Tanya_Romanova
MikeMirzayanov
6
1 2
3 4
2 1
4 3
1 4
3 2
output
Copy
I_love_I_love_I_love_Tanya_Romanova
input
Copy
5
anonymous
natalia
LeBron
Tanya_Romanova
MikeMirzayanov
3
2 1
1 2
1 5
output
Copy
I_love_MikeMirzayanov
input
Copy
2
MikhailRubinchik
evol_I
1
1 2
output
Copy
I_love_evol_I


题目大意比较简单,模拟就可以了,记录每次字符串前面I_love_的个数 level.以及最底下的字符串。最后输出即可

#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    string s[n+1];
    for(int i=1;i<=n;i++){
        cin>>s[i];
    }
    int m;
    cin>>m;
    int a[m][2];
    for(int i=0;i<m;i++){
        cin>>a[i][0]>>a[i][1];
    }
    int x=1;
    int count=0;
    for(int i=m-1;i>=0;i--){
        if(a[i][0]==x){
            x=a[i][1];
            count++;
        }
    }
    for(int i=0;i<count;i++){
        cout<<"I_love_";
    }
    cout<<s[x];
    return 0;
}

 

I love Codeforces

标签:fir   admin   ext   evel   anon   can   any   contest   inf   

原文地址:https://www.cnblogs.com/yiyunwang/p/9427283.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!