现在的位置: 首页 > 综合 > 正文

【ACM】sicily 1934

2013年12月10日 ⁄ 综合 ⁄ 共 991字 ⁄ 字号 评论关闭

// Problem#: 1934
// Submission#: 1208504
// The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
// URI: http://creativecommons.org/licenses/by-nc-sa/3.0/
// All Copyright reserved by Informatic Lab of Sun Yat-sen University
#include <stdio.h>

int pre[500001];
int nex[500001];

int main()
{
    int t;
    int n, m;
    int i,j;
    int choice, x, y;
    scanf("%d", &t);
    while(t--)
    {
        scanf("%d%d", &n, &m);
        for(i = 1; i <= n + 1; i++)
        {
            nex[i - 1] = i;
            pre[i] = i - 1;
        }
        while(m--)
        {
            scanf("%d%d%d", &choice, &x, &y);
            if(choice == 1)
            {
                nex[pre[x]] = nex[x];
                pre[nex[x]] = pre[x];

                nex[pre[y]] = x;
                pre[x] = pre[y];
                nex[x] = y;
                pre[y] = x;
            }
            else
            {
                nex[pre[x]] = nex[x];
                pre[nex[x]] = pre[x];

                nex[x] = nex[y];
                pre[nex[y]] = x;
                nex[y] = x;
                pre[x] = y;
            }
        }
        i = 1;
        j = nex[0];
        while(i <= n)
        {
            printf("%d ", j);
            j = nex[j];
            i++;
        }
        printf("\n");
    }
    return 0;
}                                 

抱歉!评论已关闭.