Problem:


Drawing Lots

Let's play Amidakuji. 

In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.

In the starting points (top of the figure), numbers are assigned to vertical lines in ascending order from left to right. At the first step, 2 and 4 are swaped by the first horizontal line which connects second and fourth vertical lines (we call this operation (2, 4)). Likewise, we perform (3, 5), (1, 2) and (3, 4), then obtain "4 1 2 5 3" in the bottom.

Your task is to write a program which reads the number of vertical lines w and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., w are assigne to the vertical lines from left to right.

Input

w
n
a1,b1
a2,b2
.
.
an,bn

w (w ≤ 30) is the number of vertical lines. n (n ≤ 30) is the number of horizontal lines. A pair of two integers ai and bi delimited by a comma represents the i-th horizontal line.

Output

The number which should be under the 1st (leftmost) vertical line

The number which should be under the 2nd vertical line

:

The number which should be under the w-th vertical line

Sample Input

5
4
2,4
3,5
1,2
3,4

Output for the Sample Input

4
1
2
5
3

Try it.
-->



Sample input:
5
4
2,4
3,5
1,2
3,4


Sample output:
4
1
2
5
3

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding:utf-8 -*-
w = int(input())
n = int(input())
v_lines = [i for i in range(1,w+1)]
for i in range(n):
    a,b = list(map(int, input().split(',')))
    t = v_lines[a-1]
    v_lines[a-1] = v_lines[b-1]
    v_lines[b-1] = t
for i in range(len(v_lines)):
    print(v_lines[i])

Submission status: Accepted

Solution code:
import sys
import math as mas

w=int(input())
n=int(input())
a=[i for i in range(1,w+1)]
for i in range(n):
	b,c=map(int,input().split(','))
	a[b-1],a[c-1]=a[c-1],a[b-1]
for i in a:print(i)

#for i in sys.stdin:
#	a,b=map(int,i.split())
#	print(gcd(a,b),lcm(a,b))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

import sys
import os
import math


tate = int(input())
yoko = int(input())
values = [i for i in range(tate)]
#print(values)

for _ in range(yoko):
    a, b = map(int, input().split(','))
    a -= 1
    b -= 1
    values[a], values[b] = values[b], values[a]

for i in values:
    print(i+1)

Submission status: Accepted

Solution code:
list = {}
for a in range(1, int(input()) + 1) : list[a] = a
for a in range(int(input())) :
    x, y = [int(temp) for temp in input().split(',')]
    temp = list[x]
    list[x] = list[y]
    list[y] = temp
for a in range(1, len(list) + 1) : print(list[a])

Submission status: Accepted

Solution code:
w = int(input())
n = int(input())
a = list(range(w))
for i in range(n):
    k1,k2 = map(int,input().split(","))
    a[k1-1],a[k2-1] = a[k2-1],a[k1-1]
for i in a:
    print(i+1)

Submission status: Accepted

Solution code:
import sys


num = input()
list = {}
for i in range(1, int(num) + 1): 
    list[i] = i
    
for i in range(int(input())) :
    x, y = map(int, input().split(','))
    
    temp = list[x]
    list[x] = list[y]
    list[y] = temp
    
for i in range(1, len(list) + 1):
    print(list[i])

Submission status: Accepted

Solution code:
import sys

lines = str(sys.stdin.read()).strip().split("\n")
W = int(lines.pop(0))
N = int(lines.pop(0))

results = list(range(1,W + 1))

for i in range(N):
    data = list(map(lambda i: int(i) - 1, lines[i].split(",")))
    results[data[0]], results[data[1]] = results[data[1]], results[data[0]]

for result in results:
	print(result)

Submission status: Accepted

Solution code:
def main():
    w = int(input())
    n = int(input())
    ans =[i for i in range(1, w+1)]

    def change(li, a, b):
        tmp = li[a-1]
        li[a-1] = li[b-1]
        li[b-1] = tmp
        return li

    for _ in range(n):
        a, b = map(int, input().split(","))
        ans = change(ans, a, b)
    print(*ans, sep="\n")


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
n = int(sys.stdin.readline().rstrip())
m = int(sys.stdin.readline().rstrip())
l = []
for i in range(m):
    l.append(list(map(int, sys.stdin.readline().rstrip().split(','))))
for i in range(n):
    cur = i+1
    for d in l[::-1]:
        if cur in d:
            cur = d[0] if cur == d[1] else d[1]
    print(cur)

Submission status: Accepted

Solution code:
w, n = int(input()), int(input())
p = list(range(1, w + 1))
l = [list(map(int, input().split(","))) for i in range(n)]
for j in l: p[j[0] - 1], p[j[1] - 1] = p[j[1] - 1], p[j[0] - 1]
k = [print(v) for v in p]

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-



def main():
    w = int(input())
    n = int(input())

    xs = [i for i in range(w+1)]
    for _ in range(n):
        a, b = map(int, input().split(","))

        xs[a], xs[b] = xs[b], xs[a]

    for i in range(1, w+1):
        print(xs[i])

if __name__ == "__main__": main()

Submission status: Accepted

Solution code:
w = int(input())
n = int(input())
am = [i for i in range(w+1)]
for _ in range(n):
    a, b = map(int, input().split(','))
    am[a], am[b] = am[b], am[a]
print(*am[1:], sep="\n")

Submission status: Accepted

Solution code:
w = int(input())
nums = list(range(w + 1))
for _ in range(int(input())):
    a, b = map(int, input().split(","))
    nums[a], nums[b] = nums[b], nums[a]
for x in nums[1:]:
    print(x)

Submission status: Accepted

Solution code:
w = int(input())
n = int(input())
a = [[int(i) for i in input().split(",")] for j in range(n)]
b = [0 for i in range(w)]
for i in range(1, w+1):
    next_num = i
    for j in a:
        if next_num == j[0]:
            next_num = j[1]
        elif next_num == j[1]:
            next_num = j[0]
    b[next_num - 1] = i
for i in range(w):
    print(b[i])

Submission status: Accepted

Solution code:
user = input()
w = int(user)
user = input()
n = int(user)
a = []
b = []
now = 0
for i in range(n):
    user = input()
    users = user.split(",")
    a.append(int(users[0]))
    b.append(int(users[1]))

for j in range(1, w+1):
    now = j
    for k in reversed(range(n)):
        if now == a[k]:
            now = b[k]
        elif now == b[k]:
            now = a[k]
    print(now)

Submission status: Accepted

Solution code:
# Aizu Problem 0011: Drawing Lots
#
import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


         
w = int(input())
slots = list(range(1, w + 1))
n = int(input())
for k in range(n):
    a, b = [int(_) for _ in input().split(',')]
    slots[a-1], slots[b-1] = slots[b-1], slots[a-1]
for s in slots:
    print(s)

Submission status: Accepted

Solution code:
w=int(input())
n=int(input())
a=[]
b=[]
Ans=[int(0) for i in range(w)]
for i in range(n):
    x,y=[int(j) for j in input().split(",")]
    a.append(x)
    b.append(y)
for i in range(1,w+1):
    ans=i
    for j in range(len(a)):
        if ans==a[j]:
            ans=b[j]
        elif ans==b[j]:
            ans=a[j]
    Ans[ans-1]=i
for i in range(w):
    print(Ans[i])

Submission status: Accepted

Solution code:
W = int(input())
N = int(input())
edges = [tuple(map(lambda c:int(c)-1, input().split(","))) for _ in [0]*N]
result = list(range(1, W+1))

for a, b in edges:
    result[a], result[b] = result[b], result[a]

print("\n".join(map(str, result)))

Submission status: Accepted

Solution code:
import sys
w = int(input())
n = int(input())
l = list()
for _ in range(n):
    l.append(list(map(int,input().split(","))))

res = [0 for _ in range(w)]
for i in range(1,w+1):
    tgt = i
    for num in l:
        if tgt in num:
            if num.index(tgt) == 1:
                tgt = num[0]
            else:
                tgt = num[1]
    res[tgt-1] = i

for x in res:
    print(x)

Submission status: Accepted

Solution code:
stick = [i for i in range(1, int(input()) + 1)]

net = int(input())

for _ in range(net):
    a, b = list(map(int, input().split(",")))
    stick[a - 1], stick[b - 1] = stick[b - 1], stick[a - 1]
for v in stick:
    print(v)

Submission status: Accepted

Solution code:

if __name__ == '__main__':
    w = (int)(input())
    n = (int)(input())
    a = [i+1 for i in range(0,w)]
    for i in range(n):
        x,y = map(int,input().split(","))
        a[x-1],a[y-1] = a[y-1],a[x-1]
    for x in a:
        print(x)

Submission status: Accepted

Solution code:
w = int(input().rstrip())
n = int(input().rstrip())

amida = [i for i in range(w)]

for i in range(n):
    a = input().rstrip().split(",")
    number = [int(i) - 1 for i in a]
    amida[number[0]], amida[number[1]] = amida[number[1]], amida[number[0]]

for i in amida:
    print(i + 1)

Submission status: Accepted

Solution code:
# coding=utf-8


def list_swap(given_list: list, swap_number1: int, swap_number2: int)-> list:
    return_list = given_list[:]
    memo = given_list[swap_number1 - 1]
    return_list[swap_number2 - 1] = memo
    memo = given_list[swap_number2 - 1]
    return_list[swap_number1 - 1] = memo
    return return_list


if __name__ == '__main__':
    w = int(input())
    amida_number = [i for i in range(1, w+1)]
    n = int(input())
    for j in range(n):
        a, b = map(int, input().split(','))
        amida_number = list_swap(amida_number[:], a, b)
    [print(amida_number[k]) for k in range(w)]

Submission status: Accepted

Solution code:
# coding: utf-8

w = int(raw_input())
n = int(raw_input())

yoko = []
for i in range(n):
	data = map(int, raw_input().split(","))
	yoko.append(data)

ans = []
for i in range(1,w+1):
	ans.append(0)

for num in range(1,w+1):
#	deb.printdebug1(num, debug)
	direction = num
	for c in yoko:
		if c[0] == direction:
#			deb.printdebug2(direction, debug)
#			deb.printdebug2(c[1], debug)
			direction = c[1]
		elif c[1] == direction:
#			deb.printdebug2(direction, debug)
#			deb.printdebug2(c[1], debug)
			direction = c[0]
	ans[direction-1] = num

for i in ans:
	print(i)

Submission status: Accepted

Solution code:
w = int(input())
n = int(input())
goal = [i for i in range(1,w+1)]
for i in range(n):
    a,b = [int(j) for j in input().split(',')]
    goal[a-1],goal[b-1] = goal[b-1],goal[a-1]
for po in goal:
    print(po)

Submission status: Accepted

Solution code:
w = int(input())
lots = [i for i in range(w)]
n = int(input())

for i in range(n):
    a, b = map(int, input().split(","))
    lots[a - 1], lots[b - 1] = lots[b - 1], lots[a - 1]

for i in range(w):
    print(lots[i] + 1)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    point = int(input())
    A = []
    for i in range(n):
        A.append(i+1)
    for i in range(point):
        a,b = map(int,input().split(","))
        A[a-1],A[b-1] = A[b-1],A[a-1]
    for value in A:
        print(value)
      


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
data = []
w = int(input())
for i in range(w):
  data.append(i+1)

n = int(input())

for line in range(n):
  a, b = [int(i) for i in input().split(',')]
  data[a-1], data[b-1] = data[b-1], data[a-1]
for d in data:
  print(d)

Submission status: Accepted

Solution code:
a = list(map(lambda x: x+1, range(int(input()))))
for _ in range(int(input())):
    m,n = map(lambda x: int(x)-1, input().split(','))
    a[m], a[n] = a[n],a[m]
for i in a:
    print(i)

Submission status: Accepted

Solution code:
w = int(raw_input())
n = int(raw_input())
list = []

for i in range(1, w+1):
    list.append(i)
    #print list
#print list[0]

for j in range(1, n+1):
    num1, num2 = map(int, raw_input().split(","))
    temp = list[num1-1]
    list[num1-1]=list[num2-1]
    list[num2-1]=temp
    #print temp

for k in range(0, w):
    print list[k]

Submission status: Accepted

Solution code:
w = int(input())
n = int(input())
l = list(range(1,w+1))
for i in range(n):
	a,b = map(int,input().split(','))
	a -= 1
	b -= 1
	l[a],l[b] = l[b],l[a]
for x in l:
	print(x)

Submission status: Accepted

Solution code:
w = int(input())
n = int(input())
kuji = [i+1 for i in range(w)]
for _ in range(n):
    a, b = map(int, input().split(','))
    kuji[a-1], kuji[b-1] = kuji[b-1], kuji[a-1]
print(*kuji, sep="\n")

Submission status: Accepted

Solution code:
w = int(input())
n = int(input())

amida = []
amida.append(-1)
for i in range(w):
    amida.append(i)

for l in range(n):
    a,b = [int(i) for i in input().split(",")]
    tmp = amida[a]
    amida[a] = amida[b]
    amida[b] = tmp

for i in range(w):
    print(amida[i+1]+1)

Submission status: Accepted

Solution code:
a=[i+1 for i in range(int(input()))]
for _ in[0]*int(input()):
 s,t=map(lambda x:int(x)-1,input().split(','))
 a[s],a[t]=a[t],a[s]
print(*a,sep='\n')

Submission status: Accepted

Solution code:
a=list(range(int(input())+1))
for _ in[0]*int(input()):
 s,t=map(int,input().split(','));a[s],a[t]=a[t],a[s]
for s in a:
 if s:print(s)

Submission status: Accepted

Solution code:
a=list(range(int(input())+1))
for _ in[0]*int(input()):s,t=map(int,input().split(','));a[s],a[t]=a[t],a[s]
for s in a:s and print(s)

Submission status: Accepted

Solution code:
tate =int(input())
yoko=int(input())
arr = [i+1 for i in range(tate)]
for j in range(yoko):
    rep1,rep2=input().split(",")
    rep1=int(rep1)-1
    rep2=int(rep2)-1
    arr[rep1],arr[rep2] = arr[rep2],arr[rep1]

for k in range(tate):
    print(arr[k])

Submission status: Accepted

Solution code:
li = list(range(1, int(input())+1))
for i in range(int(input())):
	a,b=map(int, input().split(','))
	li[a-1], li[b-1] = li[b-1], li[a-1]
for i in li:
	print(i)

Submission status: Accepted

Solution code:
# coding: utf-8
w = int(input())
ans = [i + 1 for i in range(w)]
loop = int(input())

# swap
for _ in range(loop):
    left, right = map(int, input().split(","))
    ans[left-1], ans[right-1] = ans[right-1], ans[left-1]

# result
for i in ans:
    print(i)

Submission status: Accepted

Solution code:
w=int(input())
l=[i+1 for i in range(w)]
n=int(input())
for _ in range(n):
    a,b=[int(i)-1 for i in input().split(",")]
    t=l[a]
    l[a]=l[b]
    l[b]=t
for i in l:
    print(i)

Submission status: Accepted

Solution code:
w = int(input())
n = int(input())
lst = [i + 1 for i in range(w)]
def swap(t):
  a,b = t
  temp = lst[a-1]
  lst[a-1] = lst[b-1]
  lst[b-1] = temp
for i in range(n):
  swap(tuple(map(int,input().split(","))))
for i in range(w):
  print(lst[i])

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    w = int(input())
    result = [i + 1 for i in range(w)]

    n = int(input())

    permutations = []
    for _ in range(n):
        permutations.append(map(lambda x: int(x) - 1, input().split(',')))

    for i, j in permutations:
        result[j], result[i] = result[i], result[j]

    print("\n".join(map(str, result)))

Submission status: Accepted

Solution code:
a=list(range(int(input())+1))
for _ in[0]*int(input()):s,t=map(int,input().split(','));a[s],a[t]=a[t],a[s]
[print(s)for s in a if s]

Submission status: Accepted

Solution code:
w=int(input())
n=int(input())
d=[list(map(int,input().split(',')))for i in range(n)]

結果=[0]*w
for j in range(w):
	現在位置 = j + 1
	for k1,k2 in d:
		if 現在位置==k1:
			現在位置 = k2
		elif 現在位置==k2:
			現在位置=k1
	結果[現在位置-1]=j+1
print(*結果,sep='\n')

Submission status: Accepted

Solution code:
a = [i for i in range(int(input()) + 1)]
for _ in range(int(input())):
    x, y = map(int, input().split(","))
    a[x], a[y] = a[y], a[x]
[print(e) for e in a[1:]]

Submission status: Accepted

Solution code:
w=input()
n=input()
A=[ i+1 for i in range(w)]

for i in range(n):
	a,b=map(int, raw_input().split(","))
	ta=A[a-1]
	tb=A[b-1]
	A[a-1]=tb
	A[b-1]=ta

for i in A:
	print i

Submission status: Accepted

Solution code:
w = int(input())
n = int(input())
nums = [i for i in range(1, w+1)]
ab = []
for i in range(n):
    a, b = map(int, input().split(','))
    nums[a-1], nums[b-1] = nums[b-1], nums[a-1]
for i in nums:
    print(i)

Submission status: Accepted

Solution code:
w = int(input())
n = int(input())

amida = []

for i in range(0,w+1):
    amida.append(i)
    
for i in range(n):
    ai,bi = map(int,input().split(","))
    aa = amida[ai]
    bb = amida[bi]
    amida[ai] = bb
    amida[bi] = aa
    
for i in range(1,w+1):
    print(amida[i])

Submission status: Accepted

Solution code:
w=list(range(int(input())))
sw=[list(map(int,input().split(","))) for i in range(int(input()))]
for i in sw:
    w[i[0]-1],w[i[1]-1]=w[i[1]-1],w[i[0]-1]
[print(i+1) for i in w]

Submission status: Accepted

Solution code:
w = int(input())
n = int(input())
amida = [i for i in range(1, w + 1)]
for _ in range(n):
    a, b = list(map(int, input().split(',')))
    temp = amida[a - 1]
    amida[a - 1] = amida[b - 1]
    amida[b - 1] = temp
for i in amida:
    print(i)

Submission status: Accepted

Solution code:
# AOJ 0009 Prime Number
# Python3 2018.6.9 bal4u

w = int(input())
s = [i for i in range(w+1)]
n = int(input())
for i in range(n):
    a = list(map(int, input().split(',')))
    s[a[0]], s[a[1]] = s[a[1]], s[a[0]]

for i in range(1, w+1):
    print(s[i])

Submission status: Accepted

Solution code:
arr = [i + 1 for i in range(int(input()))]
m = int(input())
for i in range(m):
    inp = list(map(int, input().split(",")))
    tmp = arr[inp[0] - 1]
    arr[inp[0] - 1] = arr[inp[1] - 1]
    arr[inp[1] - 1] = tmp
for i in range(len(arr)):
    print(arr[i])

Submission status: Accepted

Solution code:
w = input()
bar = range(w)
n = input()
p = 0
while p != n:
    rev = raw_input().split(',')
    bar[int(rev[0])-1],bar[int(rev[1])-1] = bar[int(rev[1])-1],bar[int(rev[0])-1]
    p += 1
for i in bar:
    print i+1

Submission status: Accepted

Solution code:
import sys

w = int(sys.stdin.readline())
n = int(sys.stdin.readline())
lines = list()
for line in xrange(n):
    line = sys.stdin.readline()
    line = line.strip()
    lines.append(map(int, line.split(",")))

def swap(yoko, nums):
    a, b = yoko
    a -= 1
    b -= 1
    tmp = nums[a]
    nums[a] = nums[b]
    nums[b] = tmp

nums = range(1, w+1)
for yoko in lines:
    swap(yoko, nums)

for i in nums:
    print i

Submission status: Accepted

Solution code:
list = [x+1 for x in xrange(int(input()))]
tmp = 0
for i in xrange(int(input())):
    ch = [int(x) for x in raw_input().split(",")]
    tmp = list[ch[0]-1]
    list[ch[0]-1] = list[ch[1]-1]
    list[ch[1]-1] = tmp
for x in list:
    print x

Submission status: Accepted

Solution code:
w=input()
list=range(0,w+1)
n=input()
for i in xrange(n):
    a,b=map(int,raw_input().split(','))
    tmp=list[a]
    list[a]=list[b]
    list[b]=tmp
for i in xrange(w):
    print list[i+1]

Submission status: Accepted

Solution code:
w=input()
list=range(0,w+1)
n=input()
for i in xrange(n):
    a,b=map(int,raw_input().split(','))
    tmp=list[a]
    list[a]=list[b]
    list[b]=tmp
for i in list[1:]:
    print i

Submission status: Accepted

Solution code:
#coding: utf-8   
while 1:
    try:
        v = input()
        h = input()
        n = range(1, v+1)
        for i in xrange(h):
            vl = map(int, raw_input().split(","))
            n[vl[0]-1], n[vl[1]-1] = n[vl[1]-1], n[vl[0]-1]
        for i in xrange(v):
            print n[i]
            
    except EOFError:
        break

Submission status: Accepted

Solution code:
n = input()
amd = [i+1 for i in range(n)]

m = input()

for i in range(m):
    a,b = map(int, raw_input().split(','))
    amd[a-1],amd[b-1] = amd[b-1],amd[a-1]

for am in amd :
    print am

Submission status: Accepted

Solution code:
list=range(0,input()+1)
for i in xrange(input()):
    a,b=map(int,raw_input().split(','))
    list[a],list[b]=list[b],list[a]
for i in list[1:]:
    print i

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# coding: utf-8


def func(L, pairs):
    if pairs:
        a, b = pairs.pop(0)
        L[a], L[b] = L[b], L[a]
        return func(L, pairs)
    else:
        return L


def main():
    w = int(raw_input())
    L = range(w + 1)
    n = int(raw_input())
    pairs = []
    for i in xrange(n):
        pairs.append([int(x) for x in raw_input().split(",")])

    for i in func(L, pairs)[1:]:
        print i


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
w = int(raw_input())
n = int(raw_input())
a = []
for i in range(n):
    a.append(map(int, raw_input().split(',')))
r = range(1, w + 1)
for i in a:
    tmp = r[i[0] - 1]
    r[i[0] - 1] = r[i[1] - 1]
    r[i[1] - 1] = tmp
for i in r:
    print i

Submission status: Accepted

Solution code:
amida = range(int(raw_input()) + 1)
for i in range(int(raw_input())):
    a, b = map(int, raw_input().split(','))
    amida[a], amida[b] = amida[b], amida[a]
for i in range(1, len(amida)): print amida[i]

Submission status: Accepted

Solution code:
from __future__ import (division, absolute_import, print_function,
                        unicode_literals)
from sys import stdin

L = [i + 1 for i in xrange(int(stdin.readline()))]
for _, line in zip(xrange(int(stdin.readline())), stdin):
    a, b = (int(t) - 1 for t in line.split(','))
    L[a], L[b] = L[b], L[a]
for i in L:
    print(i)

Submission status: Accepted

Solution code:
words = []
w = input()
n = input()
change = []
for val in range(1,n+1):
	x = map(int,raw_input().split(','))
	change.append(x)
kekka = range(1,w+1)
for val in range(1,n+1):
	a = kekka[change[val-1][0]-1]
	b = kekka[change[val-1][1]-1]
	kekka[change[val-1][0]-1] = b
	kekka[change[val-1][1]-1] = a
for x in kekka:
	print x

Submission status: Accepted

Solution code:
'''
Created on Mar 21, 2013

@author: wukc
'''

import sys
w=int(sys.stdin.readline())
n=int(sys.stdin.readline())
a=[i for i in range(w+1)]

for i in range(n):
    l=sys.stdin.readline()
    x,y=map(int,l.split(","))
    a[x],a[y]=a[y],a[x]
    
print("\n".join(map(str,a[1:])))

Submission status: Accepted

Solution code:
import sys
l = range(input())
n = input()
for line in sys.stdin:
    [a,b] = [int(x) for x in line.split(',')]
    tmp = l[a-1]
    l[a-1] = l[b-1]
    l[b-1] = tmp
for i in l:
    print i+1

Submission status: Accepted

Solution code:

def change(z,x,y):
    tmp = z[x-1]
    z[x-1] = z[y-1]
    z[y-1] = tmp
    return z


a = int(raw_input())
b = int(raw_input())

c = range(a)
while b > 0:
    in1,in2 = map(int,raw_input().split(','))
    c = change(c,in1,in2)
    b -= 1


for p in c:
    print p+1

Submission status: Accepted

Solution code:
import sys


class Walker:
    def __init__(self, n):
        self.start = n
        self.state = n

    def jump(self, pair):
        a, b = pair
        if self.state == a:
            self.state = b
        elif self.state == b:
            self.state = a
        return self



def to_pair(str):
    ab = str.split(',')
    a = int(ab[0])
    b = int(ab[1])
    return (a, b)



#input_file = open(sys.argv[1], "r")
#lines = input_file.readlines()
lines = sys.stdin.readlines()

w = int(lines.pop(0))
walkers = map((lambda x: Walker(x)), range(1, w+1))

lines.pop(0)

bars = map((lambda x: to_pair(x)), lines)

walkers_end = []
for walker in walkers:
    walker = reduce((lambda wkr, p: wkr.jump(p)), bars, walker)
    walkers_end.append(walker)
walkers_end.sort(lambda a, b: cmp(a.state, b.state))

for w in walkers_end:
    print w.start

Submission status: Accepted

Solution code:
w = input()
x = range(1, w+1)
n=input()
for i in range(n):
    a, b = map(int, raw_input().split(","))
    x[a-1], x[b-1] = x[b-1], x[a-1]

for e in x:
    print e

Submission status: Accepted

Solution code:
w = int(raw_input())
n = int(raw_input())
r = range(1,w+1)
for _ in range(n):
    (a, b) = map(int, raw_input().split(','))
    r[a-1], r[b-1] = r[b-1], r[a-1]
for i in r:
    print i

Submission status: Accepted

Solution code:


amida = []

def main():
	num_vlines = int(raw_input());
	num_wlines = int(raw_input());

	init_amida(num_vlines)

	count = 0;
	while count < num_wlines :
		ab = raw_input().strip().split(',')
		# print "--- input keys ---"
		# pprint.pprint(ab)
		transposition(int(ab[0]), int(ab[1]))
		# print "--- dump amida ---"
		# print amida.items()
		count += 1

	for i in range(1, num_vlines + 1):
		print amida[i]


def init_amida(num_vlines):
	for i in range(num_vlines + 1):
		amida.append(i)

	# pprint.pprint(amida)

def transposition(a, b):
	tmp = amida[a]
	amida[a] = amida[b]
	amida[b] = tmp

main()

Submission status: Accepted

Solution code:
# Drawing Lots

import sys


w = 0
n = 0
lots = None

for (i, line) in enumerate(sys.stdin):
	if i == 0:
		w = int(line)
		lots = [lot for lot in xrange(1, w+1)]
	elif i == 1:
		n = int(line)
	else:
		a, b = map(int, line.split(","))
		lots[b-1], lots[a-1] = lots[a-1], lots[b-1]

for i in xrange(w):
	print lots[i]

Submission status: Accepted

Solution code:
w = [x+1 for x in range(input())]
for x in range(input()):
    a, b = map(int, raw_input().split(","))
    tempor = w[a-1]
    w[a-1] = w[b-1]
    w[b-1] = tempor
for x in range(len(w)):
    print w[x]

Submission status: Accepted

Solution code:
import sys

def main():
	tate = int(raw_input())
	result = []
	for i in range(1, tate+1):
		result.append(i)

	yoko = int(raw_input())

	for line in sys.stdin.readlines():
		x1, x2 = map(int, line.split(","))
		x1 -= 1
		x2 -= 1
		temp = result[x2]
		result[x2] = result[x1]
		result[x1] = temp

	for num in result:
		print num
	


if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
w = list(range(1,int(raw_input())+1))
for i in range(int(raw_input())):
	a,b = map(int,raw_input().split(','))
	t = w[a-1]
	w[a-1] = w[b-1]
	w[b-1] = t
print('\n'.join(map(str,w)))

Submission status: Accepted

Solution code:
w = list(range(1,int(raw_input())+1))
for i in range(int(raw_input())):
	a,b = map(int,raw_input().split(','))
	w[a-1], w[b-1] = w[b-1], w[a-1]
print('\n'.join(map(str,w)))

Submission status: Accepted

Solution code:
W=range(1,input()+1)
N=range(input())
for i in N:
  a,b=map(int,raw_input().split(","))
  W[a-1],W[b-1]=W[b-1],W[a-1]
for e in W:print e

Submission status: Accepted

Solution code:
W=range(1,input()+1)
N=range(input())
for i in N:
  a, b = map(int,raw_input().split(","))
  W[a-1], W[b-1] = W[b-1], W[a-1]
for e in W: print e

Submission status: Accepted

Solution code:
W=range(1, input()+1)
N=range(input())
for i in N:
  a, b = map(int,raw_input().split(","))
  W[a-1], W[b-1] = W[b-1], W[a-1]
for e in W: print e

Submission status: Accepted

Solution code:
W=range(1, input()+1)
N=range(input())
for i in N:
  a, b = map(int,raw_input().split(","))
  W[a-1], W[b-1] = W[b-1], W[a-1]
for e in W:
  print e

Submission status: Accepted

Solution code:
W = range(1, input()+1)
for i in range(input()):
  a, b = map(int,raw_input().split(","))
  W[a-1], W[b-1] = W[b-1], W[a-1]
for e in W:
  print e

Submission status: Accepted

Solution code:
W = range(input()+1)
for i in range(input()):
  a, b = map(int,raw_input().split(","))
  W[a], W[b] = W[b], W[a]
for e in W[1:]:
  print e

Submission status: Accepted

Solution code:
W=range(input()+1)
for i in range(input()):
  a,b=map(int,raw_input().split(","))
  W[a],W[b]=W[b],W[a]
for e in W[1:]:print e

Submission status: Accepted

Solution code:
W=range(input()+1)
for i in range(input()):
  a,b=map(int,raw_input().split(","))
  W[a], W[b] = W[b], W[a]
for e in W[1:]:print e

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

import sys


lineNumber = 0
#for line in [ "5", "4", "2,4", "3,5", "1,2", "3,4" ]:
for line in sys.stdin.readlines():
    lineNumber += 1

    # get data
    List = map(int, line.strip().split(","))

    # initial parameter
    if lineNumber == 1:
        w = List[0]
        array = [i for i in xrange(1, w+1)]
        continue
    if lineNumber == 2: continue

    # set data
    [a, b] = List
    a -= 1; b -= 1

    # exchange
    buf = array[a]
    array[a] = array[b]
    array[b] = buf
    
for i in xrange(w):
    print array[i]

Submission status: Accepted

Solution code:
list = range(1, input() + 1)
for i in range(input()):
    a, b = map(int, raw_input().split(','))
    a -= 1
    b -= 1
    list[a], list[b] = list[b], list[a]
for i in list:
    print i

Submission status: Accepted

Solution code:
w = int(raw_input())
n = int(raw_input())

s = [i+1 for i in range(w)]
for i in range(n):
    a, b = map(int, raw_input().split(","))
    tmp = s[a-1]
    s[a-1] = s[b-1]
    s[b-1] = tmp

for i in s:
    print i

Submission status: Accepted

Solution code:
num = [x for x in range(1,int(raw_input())+1)]
n = int(raw_input())
for i in range(n):
    s,t = map(int, raw_input().split(','))
    num[s-1],num[t-1] = num[t-1],num[s-1]
for j in num: print j

Submission status: Accepted

Solution code:
w=int(raw_input())
n=int(raw_input())

ret=range(1,w+1)

for i in range(0,n):
    ab = map(int,raw_input().split(","))
    tmp = ret[ab[0]-1]
    ret[ab[0]-1] = ret[ab[1]-1]
    ret[ab[1]-1] = tmp

for i in ret:
    print i

Submission status: Accepted

Solution code:
w = int(raw_input())
bars = []
ans = [0 for i in range(w)]

for i in range(int(raw_input())):
	bars.append(map(int, raw_input().split(',')))

for i, j in zip(range(1, w+1),range(0,w)):
	for bar in bars:
		if bar[0] == i:
			i = bar[1]
		elif bar[1] == i:
			i = bar[0]
	ans[i-1] = j+1

for s in ans:
	print s

Submission status: Accepted

Solution code:
w = input()
L = range(1, w + 1)
for i in range(input()):
    a, b = map(int, raw_input().split(','))
    L[a - 1], L[b - 1] = L[b - 1], L[a - 1]
print '\n'.join(map(str, L))

Submission status: Accepted

Solution code:
a = range(int(raw_input()) + 1)
for i in range(int(raw_input())):
    p, q = map(int, raw_input().split(','))
    a[p], a[q] = a[q], a[p]
for p in a[1:]:
    print p

Submission status: Accepted

Solution code:
w = int(raw_input())
n = int(raw_input())

arr = range(1, w+1)
for i in range(n):
  a, b = map(int, raw_input().split(','))
  arr[a-1], arr[b-1] = arr[b-1], arr[a-1]

for a in arr:
  print '%d'%a

Submission status: Accepted

Solution code:
w = int(raw_input())
n = int(raw_input())
a = []
for i in range(n):
  a.append(map(int, raw_input().split(',')))
r = range(1,w + 1)
for i in a:
  tmp = r[i[0] - 1]
  r[i[0] - 1] = r[i[1] - 1]
  r[i[1] - 1] = tmp
for i in r:
  print i

Submission status: Accepted

Solution code:
w = int(input())
x = [i for i in range(w + 1)]
n = int(input())
for i in range(n):
    a, b = map(int, input().split(','))
    x[a], x[b] = x[b], x[a]
for i in range(1, w + 1):
    print(x[i])

Submission status: Accepted

Solution code:
v = int(input())
h = int(input())

l = [i for i in range(1, v + 1)]
for i in range(h):
    n, m = input().split(',')
    n = int(n) - 1
    m = int(m) - 1
    l[n], l[m] = l[m], l[n]

for i in l:
    print(i)

Submission status: Accepted

Solution code:
w = int(input())
wlist = list(range(1,w+1))
n = int(input())
for i in range(n):
    a, b = map(int, input().split(','))
    wlist[a-1], wlist[b-1] = wlist[b-1], wlist[a-1]
for i in range(w):
    print(wlist[i])

Submission status: Accepted

Solution code:
n=int(input())
k=int(input())

li=[]
for i in range(1, n+1):
    li.append(i)
    
#print(li)
for i in range(k):
    x=list(map(int,input().split(",")))
    li[x[0]-1]^=li[x[1]-1]
    li[x[1]-1]^=li[x[0]-1]
    li[x[0]-1]^=li[x[1]-1]
    #print(*li)
    
for i in range(n):
    print(li[i])

Submission status: Accepted

Solution code:
w = int(input())
n = int(input())
lst = [i for i in range(1, w+1)]
for i in range(n) :
    a, b = map(int, input().split(','))
    lst[a-1], lst[b-1] = lst[b-1], lst[a-1]
for i in lst :
    print(i)

Submission status: Accepted

Solution code:
#空リストと1~入力値までの数字を入れたリストを作成する
line = []
for i in range(1,int(input()) + 1):line.append(i)

#何処と何処を交換するかを入力し交換する
for _ in range(int(input())):
    a,b = map(int,input().split(","))
    line[a - 1],line[b - 1] = line[b - 1],line[a - 1]
    
#出力
for s in line:print(s)