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: Wrong Answer

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

import sys
import math

w = int(input())
n = int(input())
s = []

for _ in range(n):
    x = input().split(',')
    s.append((int(x[0]), int(x[1])))

result = [i for i in range(1, w+1)]
print(len(result))

for x, y in s:
    result[x-1], result[y-1] = result[y-1], result[x-1]

for x in result:
    print(x)

Submission status: Wrong Answer

Solution code:
def main():
    LIST=[]
    for i in range(int(input())):
        LIST.append(i+1)

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

    for i in LIST:
        print(i)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
a=int(input())
b=int(input())
c=range(1,b+1)
for i in range(a):
    d=str(raw_input())
    c[int(d[0])],c[int(d[-1])]=c[int(d[-1])],c[int(d[0])]
for i in c:print(i)

Submission status: Wrong Answer

Solution code:
w = int(input())
n = int(input())
Ami = []
Num = []
for i in range(n):
    Ami.append(list(map(int,input().split(","))))
print(Ami)
for i in range(1,w+1):
    pos = i
    for j in range(n):
        if pos == Ami[j][0]:
            pos = Ami[j][1]
        elif pos == Ami[j][1]:
            pos = Ami[j][0]
    Num.append([pos,i])
Num = sorted(Num)
for k in range(0,w):
    print(Num[k][1])

Submission status: Wrong Answer

Solution code:
def get_another_num(data, me):
    if data[0] == me:
        return data[1]
    else:
        return data[0]


if __name__ == '__main__':
    # ??????????????\???
    v_lines = 5
    h_lines = 4
    data = [(2, 4), (3, 5), (1, 2), (3, 4)]

    # ????????????????????????
    results = [0] * (v_lines + 1)
    for i in range(1, v_lines + 1):
        me = i
        for amida in data:
            if me in amida:
                me = get_another_num(amida, me)
        results[me] = i

    # ???????????¨???
    for i in range(1, v_lines + 1):
        print(results[i])

Submission status: Wrong Answer

Solution code:
w = int(input())
n = int(input())
array = [[i for i in input().split(",")]for i in range(n)]
a = -1
b = 1
c = False
d = [0 for i in range(w)]
for i in range(w):
    for i2 in range(n):
        if (i+1 == int(array[i2][0]) or i+1 == int(array[i2][1])) and a == -1:
            a = i2
            if i+1 == int(array[i2][0]):
                b = int(array[i2][1])
            else:
                b = int(array[i2][0])
            c = True
        if c and a < i2 and (b == int(array[i2][0]) or b == int(array[i2][1])):
            a = i2
            if b == int(array[i2][0]):
                b = int(array[i2][1])
            else:
                b = int(array[i2][0])
    d[b-1] = i+1
    a = -1
    b = i+1
    c = False
for i in range(w):
    print(d[i])

Submission status: Wrong Answer

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(','))))
print(l)
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: Wrong Answer

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]))
print(a)
print(b)

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: Wrong Answer

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]
    print(stick)
print("\n".join(map(str, stick)))

Submission status: Wrong Answer

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:print(s+1)

Submission status: Wrong Answer

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+1)

Submission status: Wrong Answer

Solution code:
import pprint

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: Wrong Answer

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: Wrong Answer

Solution code:
import sys

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

	print result

	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: Wrong Answer

Solution code:
W = range(input()+2)
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: Wrong Answer

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(',')))
print bars

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:
def run():
    w = [i + 1 for i in range(int(input()))]
    n = int(input())
    for _ in range(n):
        s1, s2 = list(map(int, input().split(',')))
        w[s1-1], w[s2-1] = w[s2-1], w[s1-1]
    print('\n'.join([str(_w) for _w in w]))

if __name__ == '__main__':
    run()

Submission status: Accepted

Solution code:
import sys

n = int(sys.stdin.readline())
sys.stdin.readline()
l = range(1, n+1)

for line in sys.stdin:
  a,b = map(int, line.strip().split(','))
  l[a-1], l[b-1] = l[b-1], l[a-1]

for x in l:
  print x

Submission status: Accepted

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

import sys

num_v = input()
num_h = input()
lis = range(num_v+1)
for s in sys.stdin:
  d = map(int , s.split(",") )
  lis[d[0]], lis[d[1]] = lis[d[1]], lis[d[0]]
for e in lis[1:]:
  print e

Submission status: Accepted

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

lis=[i+1 for i in range(w)]

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

for i in range(w):
    print(lis[i])

Submission status: Accepted

Solution code:
import sys
f = sys.stdin
w = int(f.readline())
lots = [i + 1for i in range(w)]


n = int(f.readline())
for _ in range(n):
    a, b = map(int , f.readline().split(','))
    lots[a - 1], lots[b - 1] = lots[b - 1], lots[a - 1]

for i in lots:
    print(i)

Submission status: Accepted

Solution code:
while True:
    try:
        w = int(raw_input())
        n = int(raw_input())
        ans = [j for j in range(1,w+1)]
        for k in range(n):
            a,b = map(int,(raw_input().split(",")))
            ans[a-1],ans[b-1] = ans[b-1],ans[a-1]
        for item in ans:
            print item
    except EOFError:
        break

Submission status: Accepted

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

# Copyright  : @Huki_Hara
# Created    : 2015-03-01

s=[]
W=int(input())
n=int(input())
for i in range(W):
    s.append(i+1)

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

for i in s:
    print(i)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
w=int(raw_input())

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

Submission status: Accepted

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

w = int ( input ( ) )
n = int ( input ( ) )

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

import sys
import math

w = int(input())
n = int(input())
s = []

for _ in range(n):
    x = input().split(',')
    s.append((int(x[0]), int(x[1])))

result = [i for i in range(1, w+1)]

for x, y in s:
    result[x-1], result[y-1] = result[y-1], result[x-1]

for x in result:
    print(x)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
n = input()
m = input()
line = []
for i in range(0, n):
    line.append(i)
for i in range(0, m):
    change = map(int, raw_input().split(','))
    change[0] -= 1
    change[1] -= 1
    line[change[0]], line[change[1]] = line[change[1]], line[change[0]]
for i in range(0, n):
    print line[i] + 1

Submission status: Accepted

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

Submission status: Accepted

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

nums = list(range(1, w + 1))
for i in range(n):
    ab = input().split(",")
    a = int(ab[0]) - 1
    b = int(ab[1]) - 1

    _a = nums[a]
    nums[a] = nums[b]
    nums[b] = _a
print("\n".join([str(n) for n in nums]))

Submission status: Accepted

Solution code:
# coding: utf-8
#Problem Name: Drawing Lots
#ID: tabris
#Mail: t123037@kaiyodai.ac.jp

w = int(raw_input())
n = int(raw_input())
change = [0 for _ in xrange(n)]
for i in xrange(n):
    change[i] = eval(raw_input())
List = range(1,w+1)
for i,j in change:
    List[i-1],List[j-1] = List[j-1],List[i-1]
for i in List:
    print i

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    LIST=[]
    for i in range(int(input())):
        LIST.append(i+1)

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

    for i in LIST:
        print(str(i))
            
    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
w = int(input())
n = int(input())
lines = []
for i in range(n):
    a, b = map(int, input().split(","))
    lines.append([a, b])
lines = list(reversed(lines))
for j in range(1, w + 1):
    for line in lines:
        if line[0] == j:
            j = line[1]
        elif line[1] == j:
            j = line[0]
    print(j)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
while True:
	try:
		n = int(raw_input())
		ans = [i for i in range(n+1)]
		m = int(raw_input())
		for i in range(m):
			a, b = map(int, raw_input().strip().split(','))
			t = ans[a]
			ans[a] = ans[b]
			ans[b] = t
		ans = ans[1:]
		for x in ans:
			print x
	except EOFError:
		break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

lines = sys.stdin.readlines()
w = lines[0]
n = lines[1]
exchanges = lines[2:len(lines)]

ret = list(range(1,int(w)+1))

for line in exchanges:
    line = line.split(",")
    inp = []
    for i in line:
        inp.append(int(i))
    ret[inp[0]-1],ret[inp[1]-1] = ret[inp[1]-1],ret[inp[0]-1]

for i in ret:
    print (i)

Submission status: Accepted

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

l = list(range(w + 1))

for _ in range(n):
    a, b = map(int, input().split(','))
    l[a], l[b] = l[b], l[a]

print('\n'.join([str(i) for i in l[1:]]))

Submission status: Accepted

Solution code:
#! -*- coding:utf-8 -*-
def replace(num1,num2,nums):
    tmp = nums[num1-1]
    nums[num1-1]=nums[num2-1]
    nums[num2-1]=tmp

w = input()
nums = [x+1 for x in xrange(w)]
n = input()
for x in xrange(n):
    num1,num2 = map(int,raw_input().split(","))
    replace(num1,num2,nums)
for num in nums:
    print num

Submission status: Accepted

Solution code:
while True:
    try:
        n = int(raw_input())
        ans = [i for i in range(n+1)]
        m = int(raw_input())
        for i in range(m):
            a, b = map(int, raw_input().strip().split(','))
            t = ans[a]
            ans[a] = ans[b]
            ans[b] = t
        ans = ans[1:]
        for x in ans:
            print x
    except EOFError:
        break

Submission status: Accepted

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

res = [0] * (w + 1)
for i in range(1, w + 1):
    c = i
    for a in l:
        if a[0] == c:
            c = a[1]
        elif a[1] == c:
            c = a[0]

    res[c] = i

for r in res[1:]:
    print(r)

Submission status: Accepted

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

for i in range(1, w + 1):
    c = i
    for a in l:
        if a[0] == c:
            c = a[1]
        elif a[1] == c:
            c = a[0]

    print(c)

Submission status: Accepted

Solution code:
w=int(input())
n=int(input())
A=[int(i+1) for i in range(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 i in range(w):
	print(A[i])

Submission status: Accepted

Solution code:
W = int(input())
ary = list(range(1, W + 1))
N = int(input())
for i in range(N):
    x,y = map(int,input().split(','))
    ary[x - 1], ary[y - 1] = ary[y - 1], ary[x - 1]
for i in ary:
    print(i)

Submission status: Accepted

Solution code:
#encoding=utf-8

me,ans = [],[]
x = input()
y = input()
for i in xrange(y):
    me.append(map(int,raw_input().split(",")))

for i in xrange(x):
    i += 1
    for j in xrange(y):
        if i == me[j][0]:
            i = me[j][1]
        elif i == me[j][1]:
            i = me[j][0]

    ans.append(i)
for i in xrange(x):
    for j in xrange(x):
        if i + 1 == ans[j]:
            print j + 1

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
def main():
    w = int(input())
    n = int(input())
    nums = list(range(1, w + 1))
    for _ 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)
if __name__ == '__main__':
    main()

Submission status: Accepted

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

import sys

w = int(input())
n = int(input())

lst = range(1, w+1)

for num in sys.stdin:
    nums = num.split(",")
    a1 = int(nums[0]) - 1
    b1 = int(nums[1]) - 1

    a2 = lst[a1]
    b2 = lst[b1]
    lst[a1] = b2
    lst[b1] = a2

for i in lst:
    print(i)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
w = int(input())
Ver = list(range(1, w+1))

n = int(input())

for i in range(n):
    j, k = map(int, input().split(','))

    temp = Ver[j-1]
    Ver[j-1] = Ver[k-1]
    Ver[k-1] = temp

for i in range(len(Ver)):
    print(Ver[i])

Submission status: Accepted

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

for x in li:
    print(x)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Here your code !

def change(List,a,b):
    temp = List[a-1]
    List[a-1] = List[b-1]
    List[b-1] = temp

w = input()
n = input()

Lot = [i for i in xrange(1,w+1)]

for j in xrange(n):
    l = map(int, raw_input().split(","))
    change(Lot,l[0],l[1])

for k in xrange(len(Lot)):
    print Lot[k]

Submission status: Accepted

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

state = list(range(1, w+1))

a = [None] * (n)
b = [None] * (n)
for i,line in enumerate(sys.stdin.readlines()):
   a[i], b[i] = map(int, line.split(","))

def swap(x, y):
    global state 
    temp = state[x-1]
    state[x-1] = state[y-1]
    state[y-1] = temp


for i in range(n):
    swap(a[i], b[i])

for x in state:
    print(x)

Submission status: Accepted

Solution code:
w = int(input())
arr = [i+1 for i in range(w)]
for i in range(int(input())):
    s = input().split(",")
    a,b = int(s[0]), int(s[1])
    temp = arr[a-1]
    arr[a-1] = arr[b-1]
    arr[b-1] = temp
for i in range(w):
    print(arr[i])

Submission status: Accepted

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

Submission status: Accepted

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


def solve():
    w = int(input())
    n = int(input())
    l = [i for i in range(1, w+1)]

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

    print(*l, sep='\n')

solve()

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())

ans = [i for i in range(1, w+1)]

for i in range(n):
  a, b = map(int, raw_input().split(','))

  ans[a-1], ans[b-1] = ans[b-1], ans[a-1]

for i in range(w):
  print ans[i]

Submission status: Accepted

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

ans = [i for i in range(1, w+1)]

for i in range(n):
  a, b = map(int, raw_input().split(','))

  ans[a-1], ans[b-1] = ans[b-1], ans[a-1]

for i in ans:
  print i

Submission status: Accepted

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

for i in range(n):
    ll = input().split(",")
    a, b = ll[0], ll[1]
    a = int(a)
    b = int(b)
    list.append([a,b])

# print(list)
for i in range(1,w+1):
    position = i-1

    for ll in list:
        a, b = ll[0], ll[1]
        if position == a-1:
            position = b-1
        elif position == b-1:
            position = a-1
        else:
            pass
    ans[position] = i
for j in ans:
    print(j)

Submission status: Accepted

Solution code:
w = eval(input())
n = eval(input())
numlist = [item for item in range(1, w + 1)]
for t in range(n):
	i, j = [eval(item) - 1 for item in input().split(',')]
	numlist[i], numlist[j] = numlist[j], numlist[i]
for item in numlist:
	print(item)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
w = int(input())
n = int(input())
vertical = [x for x in range(1, w + 1)]

for i in range(n):
    a, b = [int(x) - 1 for x in input().split(',')]
    vertical[a], vertical[b] = vertical[b], vertical[a]

for i in vertical:
    print(i)

Submission status: Accepted

Solution code:
w = input()
n = input()
line = [[0 for i in xrange(n)] for j in xrange(w + 1)]
for i in xrange(n):
    a, b = map(int, raw_input().split(','))
    line[a][i] = b
    line[b][i] = a
for i in xrange(1, w + 1):
    num = i
    for j in xrange(n - 1, -1, -1):
        if line[num][j] > 0: num = line[num][j]
    print num

Submission status: Accepted

Solution code:
def swap(a, b, row):
    row[a-1], row[b-1] = row[b-1], row[a-1]  

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

result = range(1, w+1)

for i in range(n):
    a, b = map(lambda x: int(x), raw_input().split(','))
    swap(a, b, result)

for x in result:
    print x

Submission status: Accepted

Solution code:
line=input()
order=[]
for i in range(line):
	order.append(i+1)

time=input()
for n in range(time):
	inp=raw_input()
	num_pre=list(inp)
	num=[]
	if num_pre.index(",")==2:
		num.append(int(num_pre[0]+num_pre[1]))
	else:
		num.append(int(num_pre[0]))
	if len(num_pre)-num_pre.index(",")==3:
		num.append(int(num_pre[-2]+num_pre[-1]))
	else:
		num.append(int(num_pre[-1]))
	a=order[num[0]-1]
	b=order[num[1]-1]
	order[num[0]-1]=b
	order[num[1]-1]=a

for m in range(line):
	print order[m]

Submission status: Accepted

Solution code:
# coding: utf-8
w=int(input())
L=[i for i in range(1,w+1)]
n=int(input())
for i in range(n):
    a,b=[int(j)-1 for j in input().split(",")]
    s=L[a]
    L[a]=L[b]
    L[b]=s
[print(i) for i in L]

Submission status: Accepted

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

for i in range(w):
    print(nums[i])

Submission status: Accepted

Solution code:
w = int(input().replace("\n", ""))
n = []
for i in range(int(input().replace("\n", ""))):
    n.append([int(v) for v in input().replace("\n", "").split(",")])

m = [0] * (w + 1)
for i in range(1, w + 1):
    step = i
    for j in range(0, len(n)):
        if n[j][0] == step:
            step = n[j][1]
        elif n[j][1] == step:
            step = n[j][0]
    m[step] = i
del m[:1]
print("\n".join(map(str, m)))

Submission status: Accepted

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

import sys

def amida(w, side_bar):
    result = []
    side_bar.reverse()
    for x in range(1, w+1):
        status = x
        for bar in side_bar:
            if status == bar[0]:
                status = bar[1]
            elif status == bar[1]:
                status = bar[0]
        result.append(status)
    return result

def main():
    W = int(input())
    N = int(input())
    side_bar = [tuple(map(int, input().split(','))) for line in range(N)]
    result = amida(W, side_bar)
    for r in result:
        print(r)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

nums = [i for i in range(1,w+1)]

for i in range(n):
    try:
        a, b = list(map(lambda x:int(x)-1, input().split(",")))
    except EOFError:
        break
    nums[a], nums[b] = nums[b], nums[a]

for i in nums:
    print(i)

Submission status: Accepted

Solution code:
w = int(input())
n = int(input())
Ami = []
Num = []
for i in range(n):
    Ami.append(list(map(int,input().split(","))))
for i in range(1,w+1):
    pos = i
    for j in range(n):
        if pos == Ami[j][0]:
            pos = Ami[j][1]
        elif pos == Ami[j][1]:
            pos = Ami[j][0]
    Num.append([pos,i])
Num = sorted(Num)
for k in range(0,w):
    print(Num[k][1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def get_another_num(data, me):
    if data[0] == me:
        return data[1]
    else:
        return data[0]


if __name__ == '__main__':
    # ??????????????\???
    #v_lines = 5
    #h_lines = 4
    #data = [(2, 4), (3, 5), (1, 2), (3, 4)]
    v_lines = int(input())
    h_lines = int(input())
    data = []
    for i in range(h_lines):
        data.append(tuple(map(int, input().split(','))))


    # ????????????????????????
    results = [0] * (v_lines + 1)
    for i in range(1, v_lines + 1):
        me = i
        for amida in data:
            if me in amida:
                me = get_another_num(amida, me)
        results[me] = i

    # ???????????¨???
    for i in range(1, v_lines + 1):
        print(results[i])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
w = [v+1 for v in range(int(input()))]
n = int(input())
for i in range(n):
    a, b = map(int, 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=eval(input())
n=eval(input())
edge=[]
for i in range(n):
    edge.append(tuple(map(int,input().split(','))))
for i in range(1,w+1):
    temp=i
    for j in range(n):
        if temp in edge[n-j-1]:
            temp=edge[n-j-1][edge[n-j-1].index(temp)-1]
    print(temp)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
 
import sys
 
def amida(w, side_bar):
    result = []
    side_bar.reverse()
    for x in range(1, w+1):
        status = x
        for bar in side_bar:
            if status == bar[0]:
                status = bar[1]
            elif status == bar[1]:
                status = bar[0]
        result.append(status)
    return result
 
def main():
    W = int(input())
    N = int(input())
    side_bar = [tuple(map(int, input().split(','))) for line in range(N)]
    result = amida(W, side_bar)
    for r in result:
        print(r)
 
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
w = int(raw_input().rstrip())

l=[]
for i in range(w+1):
  l.append(i) 

n = int(raw_input().rstrip())

for i in range(n):
  a, b = raw_input().rstrip().split(",")
  l[int(a)], l[int(b)] = l[int(b)], l[int(a)]


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

Submission status: Accepted

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

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

for i in ans:
    print(i+1)

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 i in range(w):
    print(l[i])