submission_id string | problem_id string | status string | code string | input string | output string | problem_description string |
|---|---|---|---|---|---|---|
s306823731 | p00011 | Accepted | 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 | 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s478017367 | p00011 | Accepted | 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 | 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s258728880 | p00011 | Accepted | #!/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() | 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s440971151 | p00011 | Accepted | 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 | 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s419601041 | p00011 | Accepted | 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] | 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s465595317 | p00011 | Accepted | 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) | 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s291349076 | p00011 | Accepted | 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 | 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s267842674 | p00011 | Accepted | '''
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:])))
| 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s016642632 | p00011 | Accepted | 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 | 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s274837616 | p00011 | Accepted |
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 | 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s893465178 | p00011 | Accepted | 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 | 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s197450060 | p00011 | Accepted | 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 | 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s027202546 | p00011 | Accepted | 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 | 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s584323447 | p00011 | Accepted |
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() | 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s594796472 | p00011 | Accepted | # 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] | 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s697767964 | p00011 | Accepted | 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] | 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s451426277 | p00011 | Accepted | 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() | 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s482422387 | p00011 | Accepted | 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))) | 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s998768689 | p00011 | Accepted | 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))) | 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s073629052 | p00011 | Accepted | 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 | 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s538690849 | p00011 | Accepted | 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 | 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s153472346 | p00011 | Accepted | 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 | 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s947872779 | p00011 | Accepted | 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 | 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s045789835 | p00011 | Accepted | 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 | 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s426271053 | p00011 | Accepted | 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 | 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s442211151 | p00011 | Accepted | 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 | 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s497751054 | p00011 | Accepted | 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 | 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s545382617 | p00011 | Accepted | # -*- 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]
| 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s757836953 | p00011 | Accepted | 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 | 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s110241403 | p00011 | Accepted | 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 | 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s872594072 | p00011 | Accepted | 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 | 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s107849255 | p00011 | Accepted | 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 | 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s522293993 | p00011 | Accepted | 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 | 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s792054830 | p00011 | Accepted | 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)) | 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s779750546 | p00011 | Accepted | 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 | 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s984954173 | p00011 | Accepted | 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 | 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s790071813 | p00011 | Accepted | 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 | 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s211125584 | p00011 | Accepted | 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]) | 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s425455756 | p00011 | Accepted | 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) | 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s660886706 | p00011 | Accepted | 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])
| 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s349728855 | p00011 | Accepted | 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])
| 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s584284867 | p00011 | Accepted | 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)
| 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s706578102 | p00011 | Accepted | #空リストと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)
| 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s122515904 | p00011 | Accepted | w = int(input())
n = int(input())
wlst = [i for i in range(1, w+1)]
for i in range(n):
inputlst = list(map(int, input().split(',')))
a, b = inputlst[0]-1, inputlst[1]-1
wlst[a], wlst[b] = wlst[b], wlst[a]
for i in wlst:
print(i)
| 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s386575615 | p00011 | Accepted | W = int(input())
N = int(input())
*R, = range(1, W+1)
for i in range(N):
a, b = map(int, input().split(","))
R[a-1], R[b-1] = R[b-1], R[a-1]
print(*R, sep='\n')
| 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s599912216 | p00011 | Accepted | w = int(input())
s = [i for i in range(1,w+1)]
n = int(input())
for i in range(n):
a = list(map(int, input().split(',')))
s[a[0]-1],s[a[1]-1] = s[a[1]-1],s[a[0]-1]
for i in s:
print(i)
| 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s277069813 | p00011 | Accepted | numList = []
for i in range(int(input())):
numList.append(i + 1)
for i in range(int(input())):
a, b = list(map(int, input().split(',')))
a, b = a - 1, b - 1
tmp = numList[a]
numList[a] = numList[b]
numList[b] = tmp
for num in numList:
print(num)
| 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s824011676 | p00011 | Accepted | table = [(0,0)] * 31
dp = [0] * 31
w = int(input())
h = int(input())
for i in range(1,h + 1):
a,b = (int(_) for _ in input().split(","))
table[i] = (a,b)
# あみだくじ
for i in range(1,w + 1):
dest = i
for j in range(1,h + 1):
if table[j][0] == dest:
dest = table[j][1]
elif table[j][1] == dest:
dest = table[j][0]
dp[dest] = i
for i in range(1,w + 1):
print(dp[i])
| 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s822474397 | p00011 | Accepted | W = int(input())
N = int(input())
C = [[-1 for j in range(W)] for i in range(N)]
for i in range(N):
a, b = map(lambda x:int(x) - 1, input().split(','))
C[i][a] = b
C[i][b] = a
A = [-1] * W
for n in range(W):
j = n
for i in range(N):
if C[i][j] >= 0:
j = C[i][j]
A[j] = n + 1
for v in A:
print(v)
| 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s385002818 | p00011 | Accepted | W = int(input());#list(map(int, input().split()))
N = int(input());#list(map(int, input().split()))
field=[[-1 for i in range(W)] for j in range(N)]
for i in range(N):
a,b=list(map(int, input().split(',')))
field[i][a-1]=b-1;
field[i][b-1]=a-1;
result=[0 for i in range(W)];
for i in range(W):
now=i;
for j in range(N):
if(field[j][now]!=-1):
now=field[j][now];
result[now]=i+1;
for i in result:
print(i);
| 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s379109856 | p00011 | Accepted | w = int(input())
n = int(input())
lv = [i for i in range(1, w+1)]
for _ in range(n):
a, b = list(map(int, input().split(",")))
tmp = lv[a - 1]
lv[a - 1] = lv[b - 1]
lv[b - 1] = tmp
for v in lv:
print(v)
| 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s543305156 | p00011 | Accepted | n = int(input())
m = int(input())
p = list(range(n+1))
for i in range(m):
a, b = map(int, input().split(","))
p[a], p[b] = p[b], p[a]
for v in p[1:]:
print(v)
| 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s732019303 | p00011 | Accepted | n = int(input())
h = int(input())
arr = list(range(1, n + 1))
for _ in range(h):
a, b = map(int, input().split(','))
arr[a - 1], arr[b - 1] = arr[b - 1], arr[a - 1]
for ai in arr:
print(ai)
| 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s034277383 | p00011 | Accepted | w = int(input())
n = int(input())
A = list()
B = list()
S = [i for i in range(1, w + 1)]
G = [0 for i in range(w)]
for i in range(n) :
a , b = map(int, input().split(","))
A.append(a)
B.append(b)
for i in range(1, w + 1) :
g = i
for j in range(n) :
if(A[j] == g) :
g = B[j]
elif(B[j] == g) :
g = A[j]
else :
pass
G[g - 1] = i
for i in range(w) :
print(G[i])
| 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s114166743 | p00011 | Accepted | w = int(input())
n = int(input())
L = list(range(1,w+1))
for i in range(n):
a, b = [int(x)-1 for x in input().split(",")]
L[a], L[b] = L[b], L[a]
for i in L:
print(i)
| 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s910081048 | p00011 | Accepted | w = int(input())
n = int(input())
a = range(w)
a = list(a)
for i in range(n):
p, q = map(int, input().split(","))
t = a[p - 1]
a[p - 1] = a[q - 1]
a[q - 1] = t
for each in a:
print(each + 1)
| 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s347052867 | p00011 | Accepted | w = int(input())
n = int(input())
c = list(range(0, w+1))
for i in range(n):
a, b = map(int, input().split(','))
c[a], c[b] = c[b], c[a]
for i in range(1, w + 1):
print(c[i])
| 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s752448763 | p00011 | Accepted | w = int(input())
n = int(input())
l = list(range(1,w+1))
for i in range(n):
a, b = map(int, input().split(","))
l[a-1], l[b-1] = l[b-1], l[a-1]
for i in range(w):
print(l[i])
| 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s760877214 | p00011 | Accepted | 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)
| 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s356148201 | p00011 | Accepted | 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)
| 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s046046998 | p00011 | Accepted | 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])
| 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s903566554 | p00011 | Accepted | # coding=utf-8
###
### for atcorder program
###
import sys
import math
import array
# math class
class mymath:
### pi
pi = 3.14159265358979323846264338
### Prime Number
def pnum_eratosthenes(self, n):
ptable = [0 for i in range(n+1)]
plist = []
for i in range(2, n+1):
if ptable[i]==0:
plist.append(i)
for j in range(i+i, n+1, i):
ptable[j] = 1
return plist
### GCD
def gcd(self, a, b):
if b == 0:
return a
return self.gcd(b, a%b)
### LCM
def lcm(self, a, b):
return (a*b)//self.gcd(a,b)
### Mat Multiplication
def mul(self, A, B):
ans = []
for a in A:
c = 0
for j, row in enumerate(a):
c += row*B[j]
ans.append(c)
return ans
mymath = mymath()
### output class
class output:
### list
def list(self, l):
l = list(l)
#print(" ", end="")
for i, num in enumerate(l):
print(num, end="")
if i != len(l)-1:
print(" ", end="")
print()
output = output()
### input sample
#i = input()
#N = int(input())
#A, B, C = [x for x in input().split()]
#N, K = [int(x) for x in input().split()]
#inlist = [int(w) for w in input().split()]
#R = float(input())
#A.append(list(map(int,input().split())))
#for line in sys.stdin.readlines():
# x, y = [int(temp) for temp in line.split()]
### output sample
#print("{0} {1} {2:.5f}".format(A//B, A%B, A/B))
#print("{0:.6f} {1:.6f}".format(R*R*math.pi,R*2*math.pi))
#print(" {}".format(i), end="")
def main():
W = int(input())
N = int(input())
AB = [[int(x)-1 for x in input().split(',')] for i in range(N)]
ans = list(range(1, W+1))
for ab in AB:
ans[ab[0]], ans[ab[1]] = ans[ab[1]], ans[ab[0]]
for i in ans:
print(i)
if __name__ == '__main__':
main()
| 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s908411787 | p00011 | Accepted | if __name__ == '__main__':
line = int(input())
A = [i+1 for i in range(line)]
n = int(input())
for _ in range(n):
j,k = map(int,input().split(","))
A[j-1],A[k-1] = A[k-1],A[j-1]
for i in range(line):
print(A[i])
| 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s589513386 | p00011 | Accepted | a = []
b = []
numbers_s = []
numbers_g = []
w = int(input())
n = int(input())
for i in range(0, n):
temp_a, temp_b = input().split(',')
a.append(int(temp_a))
b.append(int(temp_b))
for i in range(0, w):
numbers_s.append(i+1)
numbers_g.append(0)
for i in range(0, w):
temp_idx = i+1
for j in range(0, n):
if temp_idx == a[j]: temp_idx = b[j]
elif temp_idx == b[j]: temp_idx = a[j]
numbers_g[temp_idx - 1] = i+1
for i in range(0, len(numbers_g)):
print(numbers_g[i])
| 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s209243991 | p00011 | Accepted | w = int(input())
c = [i for i in range(1, w + 1)]
n = int(input())
for i in range(n):
a, b = map(int, input().split(","))
r = c[a - 1]
c[a - 1] = c[b - 1]
c[b - 1] = r
for i in range(w):
print(c[i])
| 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s299573050 | p00011 | Accepted | def amida():
line_number=int(input())
line=[]
for j in range(1,line_number+1):
line.append(j)
yoko=int(input())
for i in range(yoko):
a,b=map(int,input().split(","))
line[a-1],line[b-1]=line[b-1],line[a-1]
return line
while True:
try:
ans=amida()
for i in range(int(len(ans))):
print(ans[i])
break
except:break
| 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s810534703 | p00011 | Accepted | w = [i for i 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]
for i in range(len(w)):
print(w[i]+1)
| 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s824724263 | p00011 | Accepted | w = int(input())
n = int(input())
l = [i for i in range(1, w+1)]
for i in range(n):
(a,b) = map(lambda x:int(x)-1, input().strip().split(","))
(l[a],l[b]) = (l[b],l[a])
print(*l,sep="\n")
| 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s484327695 | p00011 | Accepted | w=int(input())
n=int(input())
S=[i for i in range(1,w+1)]
for i in range(n):
a,b = [int(i) for i in input().split(",")]
tmp=S[a-1]
S[a-1]=S[b-1]
S[b-1]=tmp
for i in S:
print(i)
| 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s253699594 | p00011 | Accepted | if __name__ == '__main__':
w = int(input())
n = int(input())
lst = []
anslst = [0 for i in range(w)]
for i in range(n):
a, b = map(int, input().split(','))
lst.append((a,b))
for i in range(1,w+1):
x = i
for (f,s) in lst:
if f == x:
x = s
elif s == x:
x = f
anslst[x-1] = i
for n in anslst:
print(n)
| 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s464948888 | p00011 | Accepted | #import math
w = int(input())
n = int(input())
field = [i for i in range(w+1)]
for i in range(n):
a,b = map(int,input().split(","))
field[a],field[b] = field[b],field[a]
for i in range(1,w+1):
print(field[i])
| 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s390136028 | p00011 | Accepted | 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 l:
print(i)
| 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s762845080 | p00011 | Accepted | w=int(input())
num=[i+1 for i in range(w)]
n=int(input())
for i in range(n):
data=list(map(int,input().split(",")))
a=num[data[0]-1]
num[data[0]-1]=num[data[1]-1]
num[data[1]-1]=a
for i in range(w):
if i==w-1:
print(num[i],end="\n")
else:
print(num[i])
| 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s367601756 | p00011 | Accepted | w=int(input())
n=int(input())
lst=[i+1 for i in range(w)]
for i in range(n):
x,y=map(int,input().split(","))
lst[x-1],lst[y-1]=lst[y-1],lst[x-1]
for i in lst:print(i)
| 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s649582205 | p00011 | Accepted | w = int(input())
n = int(input())
def swap(nlist,i,j):
temp = nlist[i-1]
nlist[i-1] = nlist[j-1]
nlist[j-1] = temp
return nlist
nlist = [i+1 for i in range(w)]
for i in range(n):
i,j = [int(a) for a in input().split(',')]
swap(nlist,i,j)
for i in nlist:
print(i)
| 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s531764422 | p00011 | Accepted | w = int(input())
n = int(input())
amida = [i for i in range(1, w + 1)]
for _ in range(n):
a, b = [int(i) - 1 for i in input().split(",")]
amida[a], amida[b] = amida[b], amida[a]
for x in amida:
print(x)
| 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s316603969 | p00011 | Accepted | w = int(input())
n = int(input())
alist = []
blist = []
for _ in range(n):
a, b = map(int, input().split(","))
alist.append(a)
blist.append(b)
ans = [0] * w
for i in range(1, w+1):
position = i
for a, b in zip(alist, blist):
if a == position:
position = b
elif b == position:
position = a
ans[position-1] = i
for a in ans:
print(a)
| 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s263153115 | p00011 | Accepted | w = int(input()) # 縦線
n = int(input()) # 横線
combine = [list(map(int, input().split(","))) for _ in range(n)] # 横棒の終始
answer = list(range(1, w+1)) # 回答
# 終始入れ替え
for com in combine:
x, y = com
answer[x-1], answer[y-1] = answer[y-1], answer[x-1]
# 出力(改行あり)
print('\n'.join(map(str, answer)))
| 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s335400943 | p00011 | Accepted | w = int(input())
wa = list(range(w+1))
n = int(input())
for _ in range(n):
a,b = map(int, input().split(","))
wa[a],wa[b] = wa[b],wa[a]
for s in wa[1:]:
print(s)
| 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s856639129 | p00011 | Accepted | 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")
| 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s892526571 | p00011 | Accepted | w = int(input())
bs = [ x+1 for x in range(w)]
n = int(input())
for i in range(n):
a, b = map(lambda x:int(x)-1, input().split(','))
bs[a], bs[b] = bs[b], bs[a]
[print(b) for b in bs]
| 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s052491786 | p00011 | Accepted | ans=list(range(1,int(input())+1))
for i in range(int(input())):
a,b=map(lambda x: int(x)-1,input().split(","))
ans[a],ans[b]=ans[b],ans[a]
for i in ans:
print(i)
| 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s216977384 | p00011 | Accepted | w = int(input())
n = int(input())
amida = [i+1 for i in range(w)]
for i in range(n):
a,b = map(int,input().split(","))
v = amida[a-1]
amida[a-1] = amida[b-1]
amida[b-1] = v
for i in amida:
print(i)
| 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s843696083 | p00011 | Accepted | # Drawing Lots
W = [i+1 for i in range(int(input()))]
n = int(input())
for _ in range(n):
a,b = map(int, input().split(','))
W[a-1], W[b-1] = W[b-1], W[a-1]
for w in W: print(w)
| 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s135555369 | p00011 | Runtime Error | while True:
w = int(raw_input())
n = int(raw_input())
ans = []
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 | 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s287934673 | p00011 | Runtime Error | l=xrange(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 | 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s955476104 | p00011 | Runtime Error | def play():
result_dic = {}
for i in range(tate):
depart = i+1
arrival = drawing_lots[depart][0]
arrival = aaa(depart, arrival)
result_dic[arrival] = depart
for k in sorted(result_dic):
print(result_dic[k])
def aaa(depart, arrival):
offset = 0
for point in drawing_lots[arrival]:
if point == depart:
break
offset += 1
if offset+1 <= len(drawing_lots[arrival])-1:
depart = arrival
arrival = drawing_lots[arrival][offset+1]
return aaa(depart, arrival)
else:
return arrival
tate = int(raw_input())
yoko = int(raw_input())
drawing_lots = {}
for num in range(tate):
drawing_lots[num+1] = []
for i in range(yoko):
horizontal_line = raw_input().split(',')
left_num = int(horizontal_line[0])
right_num = int(horizontal_line[1])
drawing_lots[left_num].append(right_num)
drawing_lots[right_num].append(left_num)
play() | 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s502936114 | p00011 | Runtime Error | import sys
import math
from collections import Counter
ww = raw_input()
nn = raw_input()
n = int(nn)
w = int(ww)
kuji = []
for i in range(w):
kuji.append(i+1)
for i in range(n):
l = raw_input()
a = int(l[0])
b = int(l[2])
temp = kuji[a-1]
kuji[a-1] = kuji[b-1]
kuji[b-1] = temp
for i in range(w):
print kuji[i] | 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s271457283 | p00011 | Runtime Error | import sys
import math
from collections import Counter
ww = raw_input()
nn = raw_input()
n = int(nn)
w = int(ww)
kuji = []
for i in range(w):
kuji.append(i+1)
while n > 0:
l = raw_input()
a = int(l[0])
b = int(l[2])
temp = kuji[a-1]
kuji[a-1] = kuji[b-1]
kuji[b-1] = temp
n -= 1
for i in range(w):
print kuji[i] | 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s340065514 | p00011 | Runtime Error |
import sys
import math
from collections import Counter
ww = raw_input()
nn = raw_input()
n = int(nn)
w = int(ww)
k = []
for i in range(w):
k.append(i+1)
while 1:
if n == 0:
break
l = raw_input()
a = int(l[0])
b = int(l[2])
temp = k[a-1]
k[a-1] = k[b-1]
k[b-1] = temp
n -= 1
for i in range(w):
print k[i] | 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s130751996 | p00011 | Runtime Error | import sys
import math
from collections import Counter
w = input()
n = input()
k = []
for i in range(w+1):
k.append(i)
for i in range(n):
l = raw_input()
a = int(l[0])
b = int(l[2])
temp = k[a]
k[a] = k[b]
k[b] = temp
for i in range(w):
print k[i+1] | 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s573022084 | p00011 | Runtime Error |
import sys
import math
w = input()
n = input()
k = []
for i in range(w+1):
k.append(i)
for i in range(n):
l = raw_input()
a = int(l[0])
b = int(l[2])
temp = k[a]
k[a] = k[b]
k[b] = temp
for i in range(w):
print k[i+1] | 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s004072541 | p00011 | Runtime Error |
w = int(input())
n = int(input())
k = []
for i in range(w+1):
k.append(i)
for j in range(n):
l = raw_input()
a = int(l[0])
b = int(l[2])
temp = k[a]
k[a] = k[b]
k[b] = temp
for l in range(w):
print k[l+1] | 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s173097052 | p00011 | Runtime Error | def f1(x, y):
if not x in data:
data[x] = [y]
else:
data[x].append(y)
def f2():
for i in range(1, w+1):
f3(data[i][0], i, i)
else:
for a in ans:
print a
def f3(a, b, c):
for i, num in enumerate(data[a]):
if num == b:
if i+1 < len(data[a]):
return f3(data[a][i+1], a, c)
else:
ans[a-1] = c
break
w = int(raw_input())
n = int(raw_input())
ans = [0 for i in range(1, w+1)]
data = {}
for i in range(n):
a, b = map(int, raw_input().split(','))
f1(a, b)
f1(b, a)
else:
f2() | 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s327219179 | p00011 | Runtime Error | def f1(x, y):
if not x in data:
data[x] = [y]
else:
data[x].append(y)
def f2():
for i in range(1, w+1):
f3(data[i][0], i, i)
else:
for a in ans:
print a
def f3(a, b, c):
for i, num in enumerate(data[a]):
if num == b:
if i+1 < len(data[a]):
return f3(data[a][i+1], a, c)
else:
ans[a-1] = c
break
w = int(raw_input())
n = int(raw_input())
ans = [0 for i in range(w)]
data = {}
for i in range(n):
a, b = map(int, raw_input().split(','))
f1(a, b)
f1(b, a)
else:
f2() | 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s788301171 | p00011 | Runtime Error | def play():
result_dic = {}
for i in range(tate):
depart = i+1
arrival = drawing_lots[depart][0]
arrival = aaa(depart, arrival)
result_dic[arrival] = depart
for k in sorted(result_dic):
print(result_dic[k])
def aaa(depart, arrival):
offset = 0
for offset, point in enumerate(drawing_lots[arrival]):
if point == depart:
break
if offset+1 <= len(drawing_lots[arrival])-1:
depart = arrival
arrival = drawing_lots[arrival][offset+1]
return aaa(depart, arrival)
else:
return arrival
tate = int(raw_input())
yoko = int(raw_input())
drawing_lots = {}
for num in range(tate):
drawing_lots[num+1] = []
for i in range(yoko):
horizontal_line = raw_input().split(',')
left_num = int(horizontal_line[0])
right_num = int(horizontal_line[1])
drawing_lots[left_num].append(right_num)
drawing_lots[right_num].append(left_num)
play() | 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s646828689 | p00011 | Runtime Error | w = int(raw_input())
n = int(raw_input())
l = [i for i in range(1,w+1)]
while n > 0:
a,b = map(int,raw_input().split(','))
l[a-1],l[b-1] = l[b-1],l[a-1]
n -= 1
for i in l:
print(i) | 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s465747216 | p00011 | Runtime Error | a=int(input())
b=int(input())
c=range(1,b+1)
for i in range(a):
d,e=map(int,raw_input().split())
c[d],c[e]=c[e],c[d]
[print(i) for i in c] | 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s324265076 | p00011 | Runtime Error | a=int(input())
b=int(input())
c=range(1,b+1)
for i in range(a):
d,e=map(int,raw_input().split())
c[d],c[e]=c[e],c[d]
for i in c:print(i) | 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
s555567128 | p00011 | Runtime Error | a=int(input())
b=int(input())
c=range(1,b+1)
for i in range(a):
d=map(int,raw_input().split())
c[d[0]],c[d[-1]]=c[d[-1]],c[d[0]]
for i in c:print(i) | 5
4
2,4
3,5
1,2
3,4
| 4
1
2
5
3
|
<H1>Drawing Lots</H1>
<p>
Let's play Amidakuji.
</p>
<p>
In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines.
</p>
<center>
<img src="https://judgeapi.u-aizu.ac.jp/resources/images/IMAGE1_amida1">
</center>
<br>
<p>
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.
</p>
<p>
Your task is to write a program which reads the number of vertical lines <var>w</var> and configurations of horizontal lines and prints the final state of the Amidakuji. In the starting pints, numbers 1, 2, 3, ..., <var>w</var> are assigne to the vertical lines from left to right.
</p>
<H2>Input</H2>
<pre>
<var>w</var>
<var>n</var>
<var>a<sub>1</sub></var>,<var>b<sub>1</sub></var>
<var>a<sub>2</sub></var>,<var>b<sub>2</sub></var>
.
.
<var>a<sub>n</sub></var>,<var>b<sub>n</sub></var>
</pre>
<p>
<var>w</var> (<var>w</var> ≤ 30) is the number of vertical lines. <var>n</var> (<var>n</var> ≤ 30) is the number of horizontal lines. A pair of two integers <var>a<sub>i</sub></var> and <var>b<sub>i</sub></var> delimited by a comma represents the <var>i</var>-th horizontal line.
</p>
<H2>Output</H2>
<p>
The number which should be under the 1st (leftmost) vertical line<br>
The number which should be under the 2nd vertical line<br>
:<br>
The number which should be under the <var>w</var>-th vertical line<br>
</p>
<H2>Sample Input</H2>
<pre>
5
4
2,4
3,5
1,2
3,4
</pre>
<H2>Output for the Sample Input</H2>
<pre>
4
1
2
5
3
</pre>
<!--
<H2>Hint</H2>
<a href="IMAGE1/lots.gif">Try it.</a>
-->
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.