luogu P1160 队列安排
二次联通门 :luogu P1160 队列安排
/* luogu P1160 队列安排 链表 手动模拟一下就好了。。。 */ #include <cstdio> #define Max 500009 void read (int &now) { now = 0; register char word = getchar (); while (word < '0' || word > '9') word = getchar (); while (word >= '0' && word <= '9') { now = now * 10 + word - '0'; word = getchar (); } } struct Edge { int from; int next; }; Edge mate[Max]; int edge_list[Max]; int Edge_Count; int N, M; int main (int argc, char *argv[]) { read (N); int type; int x; mate[0].next = 1; mate[1].from = 0; for (int i = 2; i <= N; i++) { read (x); read (type); if (type) { mate[i].from = x; mate[i].next = mate[x].next; mate[mate[i].next].from = i; mate[x].next = i; } else { mate[i].from = mate[x].from; mate[mate[i].from].next = i; mate[i].next = x; mate[x].from = i; } } read (N); register int now; while (N--) { read (x); if (!mate[x].next && !mate[x].from) continue; mate[mate[x].from].next = mate[x].next; mate[mate[x].next].from = mate[x].from; mate[x].from = 0; mate[x].next = 0; } now = mate[0].next; for (now = mate[0].next; now; now = mate[now].next) printf ("%d ", now); putchar ('\n'); return 0; }
myj 吊打我Orz,xxy 捆起来打我Orz,myl 文化课上天Orz, lrh 姿势水平敲高Orz, hkd 特别胖Orz%%%,cys 智商感人Orz,syl zz专业Orz,我没有学上, 我们未来一片光明