AtCoder Beginner Contest 225 D - Play Train


题意


题解

手动做链表模拟



#include #include #include using namespace std; const int MAXN = 2e5; struct Car { int front, back; }tr[MAXN]; int vec[MAXN]; int main() { int n, q; scanf("%d%d", &n, &q); for (int i = 1; i <= q; i++) { int opt; scanf("%d", &opt); if (opt == 1) { int x, y; scanf("%d%d", &x, &y); tr[y].front = x; tr[x].back = y; } if (opt == 2) { int x, y; scanf("%d%d", &x, &y); tr[y].front = 0; tr[x].back = 0; } if (opt == 3) { int x; scanf("%d", &x); int front = x; while (tr[front].front != 0)front = tr[front].front; int num = 0; vec[++num] = front; while (tr[front].back != 0) { vec[++num] = tr[front].back; front = tr[front].back; } printf("%d ", num); for (int i = 1; i <= num; i++) { printf("%d ", vec[i]); } printf("\n"); } } return 0; }

TRANSLATE with x English
Arabic Hebrew Polish
Bulgarian Hindi Portuguese
Catalan Hmong Daw Romanian
Chinese Simplified Hungarian Russian
Chinese Traditional Indonesian Slovak
Czech Italian Slovenian
Danish Japanese Spanish
Dutch Klingon Swedish
English Korean Thai
Estonian Latvian Turkish
Finnish Lithuanian Ukrainian
French Malay Urdu
German Maltese Vietnamese
Greek Norwegian Welsh
Haitian Creole Persian  
Bing Webmaster Portal Back