Untitled
unknown
c_cpp
10 months ago
1.4 kB
8
Indexable
#include <bits/stdc++.h>
using namespace std;
#define IOF ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
#define ll long long
#define ull unsigned long long
#define fi first
#define se second
#define all(v) v.begin(), v.end()
#define allR(v) v.rbegin(), v.rend()
#define sz(x) (int)x.size()
const double eps = 1e-9;
const int N = 1e5 + 5;
const int M = 1e9 + 7;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
typedef __gnu_pbds::tree<int, __gnu_pbds::null_type, less<>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update> ordered_set;
void FIO() {
#ifndef ONLINE_JUDGE
freopen("../in.txt", "r", stdin);
freopen("../out.txt", "w", stdout);
#endif
}
int dx[]{0, 1, 0, -1, 1, 1, -1, -1};
int dy[]{1, 0, -1, 0, 1, -1, -1, 1};
char di[]{'R', 'D', 'L', 'U'};
void multiVerse() {
int n;
cin >> n;
map<string, string> mp;
for (int i = 0; i < n; ++i) {
string s, t;
cin >> s >> t;
for (auto &j: mp) {
if (s == j.se) {
s = j.fi;
break;
}
}
mp[s] = t;
}
cout << sz(mp) << '\n';
for (auto &i: mp) {
cout << i.fi << " " << i.se << '\n';
}
}
int main() {
IOF
FIO();
int tt = 1;
// cin >> tt;
while (tt--) {
multiVerse();
}
return 0;
}Editor is loading...
Leave a Comment