-
Notifications
You must be signed in to change notification settings - Fork 0
/
misha_and_changing_handles.cpp
55 lines (52 loc) · 1.28 KB
/
misha_and_changing_handles.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;i++)
#define sq(a) (a)*(a)
#define vi vector<int>
#define mp make_pair
#define ii pair<int,int>
#define vii vector<ii>
int main(){
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
// int t;
// cin>>t;
// while(t--){
int n;
cin>>n;
vector<tuple<int,string,string>> s;
rep(i,0,n){
string a,b;
cin>>a>>b;
s.pb(make_tuple(0,a,b));
}
while(!s.empty()){
int flag=1;
rep(i,0,s.size()-1){
rep(j,i,s.size()){
if(get<2>(s[i])==get<1>(s[j])){
get<2>(s[i])=get<2>(s[j]);
s.erase(s.begin()+j);
get<0>(s[i])++;
flag=0;
}
}
}
if(flag){
break;
}
}
sort(s.begin(),s.end());
cout<<s.size()<<endl;
rep(i,0,s.size()){
cout<<get<1>(s[i])<<" "<<get<2>(s[i])<<endl;
}
// }
}