1. 程式人生 > 其它 >AtCoder Beginner Contest 225 D - Play Train

AtCoder Beginner Contest 225 D - Play Train

題意


題解

手動做連結串列模擬



#include<cstdio> #include<iostream> #include<vector> 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
TRANSLATE with COPY THE URL BELOW Back EMBED THE SNIPPET BELOW IN YOUR SITE Enable collaborative features and customize widget:
Bing Webmaster Portal
Back