二次联通门 :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;
}

 

相关文章:

  • 2021-05-19
  • 2021-09-09
  • 2022-12-23
  • 2021-04-12
  • 2022-01-25
  • 2021-06-09
猜你喜欢
  • 2021-05-25
  • 2022-03-03
  • 2021-12-05
  • 2021-11-29
  • 2021-07-31
  • 2021-09-22
  • 2021-08-04
相关资源
相似解决方案