只能说这题体现了map的能力很强大
#include<bits/stdc++.h>
using namespace std;
const int N = 1010;
int main(){
map<string,string> m;
int n;
cin>>n;
string a,b;
while(n--){
cin>>a>>b;
if(m.count(a)==0){
m[a] = a;
}
m[b] = m[a];
m.erase(a);
}
cout<<m.size()<<endl;
for(auto it=m.begin();it!=m.end();it++){
cout<<it->second<<" "<<it->first<<endl;
}
}