EEOJ/OJ2/map.cpp

40 lines
872 B
C++

#include<stdio.h>
#include<unordered_map>
#pragma warning(disable:4996)
using namespace std;
int main() {
unordered_map<int, pair<int, int>> mainMap;
int choice;
int total;
int x;
int y;
scanf("%d", &total);
mainMap[0] = { 1,1 };
mainMap[1] = { 0,0 };
for (int i = 0; i < total; i++) {
scanf("%d", &choice);
if (choice == 1) {
scanf("%d", &x);
scanf("%d", &y);
mainMap[y] = { x,mainMap[x].second };
mainMap[mainMap[x].second].first = y;
mainMap[x].second = y;
}
else if (choice == 2) {
scanf("%d", &x);
printf("%d\n", mainMap[x].second);
}
else if (choice == 3) {
scanf("%d", &x);
mainMap[mainMap[x].first].second = mainMap[x].second;
mainMap[mainMap[x].second].first = mainMap[x].first;
mainMap.erase(x);
}
}
int no = 0;
do {
no = mainMap[no].second;
if (no != 0)
printf("%d\n", no);
} while (no != 0);
}