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;
}

 

posted @ 2017-04-19 20:25  ZlycerQan  阅读(200)  评论(0编辑  收藏  举报