EEOJ/OJ2/main.cpp

39 lines
832 B
C++
Raw Permalink Normal View History

2024-07-03 16:37:16 +00:00
#include<stdio.h>
#include<utility>
#pragma warning(disable:4996)
using namespace std;
int main() {
pair<int,int> mainMap[100000];
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;
}
}
int no = 0;
do {
no = mainMap[no].second;
if (no != 0)
printf("%d\n", no);
} while (no != 0);
}