zoukankan      html  css  js  c++  java
  • 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 ('
    ');
        return 0;
    }
  • 相关阅读:
    C# 调用外部程序Process类
    Wix学习整理(1)——快速入门HelloWorld
    InstallShield修改XML配置文件
    小公式
    EOJ11月月赛
    长春
    贪心[偏序+treap]
    哈希
    莫比乌斯反演
    Android 编程规范
  • 原文地址:https://www.cnblogs.com/ZlycerQan/p/6735675.html
Copyright © 2011-2022 走看看