Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <array>
- #include <iostream>
- #include <vector>
- #include <map>
- using namespace std;
- #define int long long
- const long long INF = 1e18 + 7;
- const int MAXN = 2e5 + 10;
- const int N = 2e5;
- signed main() {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- int n;
- cin >> n;
- map<string, string> start, tmp;
- for (int i = 0; i < n; ++i) {
- string old, nw;
- cin >> old >> nw;
- if (!tmp.contains(old)) {
- start[old] = nw;
- tmp[nw] = old;
- } else {
- string cur = tmp[old];
- start[cur] = nw;
- tmp[nw] = cur;
- }
- }
- cout << start.size() << '\n';
- for (auto& [x, y]: start) {
- cout << x << ' ' << y << '\n';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment