Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <queue>
- #include <vector>
- #include <cstdio>
- #define task "PAINT"
- using namespace std;
- using ll = long long;
- using ld = long double;
- const int N = 30 + 2;
- const int M = 1e6 + 1;
- int n, m(0);
- queue<int> s;
- vector<int> v[N];
- char c[M];
- void Read(){
- cin >> n;
- for(int i = 1; i <= n; ++i)
- s.push(i);
- while(n--){
- int t; cin >> t;
- if(t == 1){
- m = max(m, s.front());
- char a; cin >> a;
- c[s.front()] = a;
- v[a - 'a'].push_back(s.front());
- s.pop();
- }
- else{
- char a, b;
- cin >> a >> b;
- if(a != b){
- for(auto i : v[a - 'a'])
- v[b - 'a'].push_back(i), c[i] = b;
- v[a - 'a'].clear();
- }
- }
- }
- }
- void Solve(){
- for(int i = 1; i <= m; ++i)
- cout << c[i];
- }
- main(){
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0); if(fopen(task".INP", "r"))
- freopen(task".INP", "r", stdin),
- freopen(task".OUT", "w", stdout);
- Read();
- Solve();
- }
Advertisement
Add Comment
Please, Sign In to add comment