submission_id
string
problem_id
string
status
string
code
string
input
string
output
string
problem_description
string
s306872850
p00011
Accepted
W = int(input()) ary = list(range(1, W + 1)) N = int(input()) for i in range(N): x,y = map(int,input().split(',')) ary[x - 1], ary[y - 1] = ary[y - 1], ary[x - 1] for i in ary: print(i)
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s446095647
p00011
Accepted
#encoding=utf-8 me,ans = [],[] x = input() y = input() for i in xrange(y): me.append(map(int,raw_input().split(","))) for i in xrange(x): i += 1 for j in xrange(y): if i == me[j][0]: i = me[j][1] elif i == me[j][1]: i = me[j][0] ans.append(i) for i in xrange(x): for j in xrange(x): if i + 1 == ans[j]: print j + 1
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s733660262
p00011
Accepted
#!/usr/bin/env python3 def main(): w = int(input()) n = int(input()) nums = list(range(1, w + 1)) for _ in range(n): a, b = map(int, input().split(',')) nums[a - 1], nums[b - 1] = nums[b - 1], nums[a - 1] for i in nums: print(i) if __name__ == '__main__': main()
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s934391908
p00011
Accepted
#!/usr/bin/env python #-*- coding: utf-8 -*- import sys w = int(input()) n = int(input()) lst = range(1, w+1) for num in sys.stdin: nums = num.split(",") a1 = int(nums[0]) - 1 b1 = int(nums[1]) - 1 a2 = lst[a1] b2 = lst[b1] lst[a1] = b2 lst[b1] = a2 for i in lst: print(i)
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s452041402
p00011
Accepted
# -*- coding: utf-8 -*- w = int(raw_input()) num = [] for i in range(w+1): num.append(i) n = int(raw_input()) for i in range(n): a, b = map(int, raw_input().split(',')) num[a], num[b] = num[b], num[a] for i in range(1, w+1): print num[i]
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s931176110
p00011
Accepted
w = int(input()) Ver = list(range(1, w+1)) n = int(input()) for i in range(n): j, k = map(int, input().split(',')) temp = Ver[j-1] Ver[j-1] = Ver[k-1] Ver[k-1] = temp for i in range(len(Ver)): print(Ver[i])
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s531849800
p00011
Accepted
w = int(input()) n = int(input()) li = list(range(1, w + 1)) for i in range(n): a, b = map(int, input().split(',')) a -= 1; b -= 1 li[a], li[b] = li[b], li[a] for x in li: print(x)
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s839307347
p00011
Accepted
w=input() amida=[i+1 for i in xrange(w)] n=input() for i in xrange(n): a,b=map(int,raw_input().split(",")) amida[a-1],amida[b-1]=amida[b-1],amida[a-1] for i in xrange(w): print(amida[i])
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s794430577
p00011
Accepted
# coding: utf-8 # Here your code ! def change(List,a,b): temp = List[a-1] List[a-1] = List[b-1] List[b-1] = temp w = input() n = input() Lot = [i for i in xrange(1,w+1)] for j in xrange(n): l = map(int, raw_input().split(",")) change(Lot,l[0],l[1]) for k in xrange(len(Lot)): print Lot[k]
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s947283344
p00011
Accepted
import sys w = int(input()) n = int(input()) state = list(range(1, w+1)) a = [None] * (n) b = [None] * (n) for i,line in enumerate(sys.stdin.readlines()): a[i], b[i] = map(int, line.split(",")) def swap(x, y): global state temp = state[x-1] state[x-1] = state[y-1] state[y-1] = temp for i in range(n): swap(a[i], b[i]) for x in state: print(x)
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s820395320
p00011
Accepted
w = int(input()) arr = [i+1 for i in range(w)] for i in range(int(input())): s = input().split(",") a,b = int(s[0]), int(s[1]) temp = arr[a-1] arr[a-1] = arr[b-1] arr[b-1] = temp for i in range(w): print(arr[i])
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s604027081
p00011
Accepted
w = input() n = input() kuji = [i for i in range(w)] for i in range(n): a, b = map(int, raw_input().split(",")) kuji[a-1], kuji[b-1] = kuji[b-1], kuji[a-1] for i in kuji: print i+1
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s107873594
p00011
Accepted
# -*- coding: utf-8 -*- def solve(): w = int(input()) n = int(input()) l = [i for i in range(1, w+1)] for _ in range(n): a, b = map(int, input().split(',')) a -= 1 b -= 1 l[a], l[b] = l[b], l[a] print(*l, sep='\n') solve()
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s351105509
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s873506475
p00011
Accepted
w = int(raw_input()) n = int(raw_input()) ans = [i for i in range(1, w+1)] for i in range(n): a, b = map(int, raw_input().split(',')) ans[a-1], ans[b-1] = ans[b-1], ans[a-1] for i in range(w): print ans[i]
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s696638606
p00011
Accepted
w = int(raw_input()) n = int(raw_input()) ans = [i for i in range(1, w+1)] for i in range(n): a, b = map(int, raw_input().split(',')) ans[a-1], ans[b-1] = ans[b-1], ans[a-1] for i in ans: print i
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s563048553
p00011
Accepted
w = int(input()) n = int(input()) ans = [0 for i in range(w)] list = [] for i in range(n): ll = input().split(",") a, b = ll[0], ll[1] a = int(a) b = int(b) list.append([a,b]) # print(list) for i in range(1,w+1): position = i-1 for ll in list: a, b = ll[0], ll[1] if position == a-1: position = b-1 elif position == b-1: position = a-1 else: pass ans[position] = i for j in ans: print(j)
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s569958888
p00011
Accepted
w = eval(input()) n = eval(input()) numlist = [item for item in range(1, w + 1)] for t in range(n): i, j = [eval(item) - 1 for item in input().split(',')] numlist[i], numlist[j] = numlist[j], numlist[i] for item in numlist: print(item)
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s801982435
p00011
Accepted
w=list(range(int(input())+1)) for _ in[0]*int(input()): a,b=map(int,input().split(',')) w[a],w[b]=w[b],w[a] for i in range(1,len(w)):print(w[i])
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s337685542
p00011
Accepted
w = int(input()) n = int(input()) vertical = [x for x in range(1, w + 1)] for i in range(n): a, b = [int(x) - 1 for x in input().split(',')] vertical[a], vertical[b] = vertical[b], vertical[a] for i in vertical: print(i)
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s543249229
p00011
Accepted
w = input() n = input() line = [[0 for i in xrange(n)] for j in xrange(w + 1)] for i in xrange(n): a, b = map(int, raw_input().split(',')) line[a][i] = b line[b][i] = a for i in xrange(1, w + 1): num = i for j in xrange(n - 1, -1, -1): if line[num][j] > 0: num = line[num][j] print num
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s966618110
p00011
Accepted
def swap(a, b, row): row[a-1], row[b-1] = row[b-1], row[a-1] w = int(raw_input()) n = int(raw_input()) result = range(1, w+1) for i in range(n): a, b = map(lambda x: int(x), raw_input().split(',')) swap(a, b, result) for x in result: print x
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s722067831
p00011
Accepted
line=input() order=[] for i in range(line): order.append(i+1) time=input() for n in range(time): inp=raw_input() num_pre=list(inp) num=[] if num_pre.index(",")==2: num.append(int(num_pre[0]+num_pre[1])) else: num.append(int(num_pre[0])) if len(num_pre)-num_pre.index(",")==3: num.append(int(num_pre[-2]+num_pre[-1])) else: num.append(int(num_pre[-1])) a=order[num[0]-1] b=order[num[1]-1] order[num[0]-1]=b order[num[1]-1]=a for m in range(line): print order[m]
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s024775993
p00011
Accepted
# coding: utf-8 w=int(input()) L=[i for i in range(1,w+1)] n=int(input()) for i in range(n): a,b=[int(j)-1 for j in input().split(",")] s=L[a] L[a]=L[b] L[b]=s [print(i) for i in L]
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s609288820
p00011
Accepted
w = int(input()) n = int(input()) nums = list(range(1, w + 1)) for i in range(n): a, b = map(int, input().split(",")) c = nums[a - 1] nums[a - 1] = nums[b - 1] nums[b - 1] = c for i in range(w): print(nums[i])
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s511017620
p00011
Accepted
w = int(input().replace("\n", "")) n = [] for i in range(int(input().replace("\n", ""))): n.append([int(v) for v in input().replace("\n", "").split(",")]) m = [0] * (w + 1) for i in range(1, w + 1): step = i for j in range(0, len(n)): if n[j][0] == step: step = n[j][1] elif n[j][1] == step: step = n[j][0] m[step] = i del m[:1] print("\n".join(map(str, m)))
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s772745171
p00011
Accepted
# -*- coding: utf-8 -*- import sys def amida(w, side_bar): result = [] side_bar.reverse() for x in range(1, w+1): status = x for bar in side_bar: if status == bar[0]: status = bar[1] elif status == bar[1]: status = bar[0] result.append(status) return result def main(): W = int(input()) N = int(input()) side_bar = [tuple(map(int, input().split(','))) for line in range(N)] result = amida(W, side_bar) for r in result: print(r) if __name__ == '__main__': main()
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s125398381
p00011
Accepted
li = [i for i in range(int(input())+1)] for i in range(int(input())): line = list(map(int, input().split(','))) li[line[0]],li[line[1]] = li[line[1]],li[line[0]] for i in li[1::]: print(i)
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s792696100
p00011
Accepted
w = input() n = input() A = range(1, w+1) for _ in xrange(n): a, b = map(int, raw_input().split(',')) A[a-1], A[b-1] = A[b-1], A[a-1] for a in A: print a
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s179830429
p00011
Accepted
w = int(input()) n = int(input()) nums = [i for i in range(1,w+1)] for i in range(n): try: a, b = list(map(lambda x:int(x)-1, input().split(","))) except EOFError: break nums[a], nums[b] = nums[b], nums[a] for i in nums: print(i)
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s663472564
p00011
Accepted
w = int(input()) n = int(input()) Ami = [] Num = [] for i in range(n): Ami.append(list(map(int,input().split(",")))) for i in range(1,w+1): pos = i for j in range(n): if pos == Ami[j][0]: pos = Ami[j][1] elif pos == Ami[j][1]: pos = Ami[j][0] Num.append([pos,i]) Num = sorted(Num) for k in range(0,w): print(Num[k][1])
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s735507488
p00011
Accepted
w=int(input()) n=int(input()) v=list(range(1,w+1)) for i in range(n): a,b=map(int,input().split(",")) v[a-1],v[b-1]=v[b-1],v[a-1] for i in range(w): print(v[i])
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s375797586
p00011
Accepted
def get_another_num(data, me): if data[0] == me: return data[1] else: return data[0] if __name__ == '__main__': # ??????????????\??? #v_lines = 5 #h_lines = 4 #data = [(2, 4), (3, 5), (1, 2), (3, 4)] v_lines = int(input()) h_lines = int(input()) data = [] for i in range(h_lines): data.append(tuple(map(int, input().split(',')))) # ???????????????????????? results = [0] * (v_lines + 1) for i in range(1, v_lines + 1): me = i for amida in data: if me in amida: me = get_another_num(amida, me) results[me] = i # ???????????¨??? for i in range(1, v_lines + 1): print(results[i])
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s789694844
p00011
Accepted
w = int(input()) amida = list(range(1,w+1)) n = int(input()) for i in range(0,n): exchange = list(map(int,input().split(","))) amida[exchange[1]-1], amida[exchange[0]-1] = amida[exchange[0]-1], amida[exchange[1]-1] for i in amida: print(i)
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s789704203
p00011
Accepted
w = [v+1 for v in range(int(input()))] n = int(input()) for i in range(n): a, b = map(int, input().split(",")) w[a-1], w[b-1] = w[b-1], w[a-1] print('\n'.join(map(str, w)))
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s513334113
p00011
Accepted
w=eval(input()) n=eval(input()) edge=[] for i in range(n): edge.append(tuple(map(int,input().split(',')))) for i in range(1,w+1): temp=i for j in range(n): if temp in edge[n-j-1]: temp=edge[n-j-1][edge[n-j-1].index(temp)-1] print(temp)
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s226792292
p00011
Accepted
i=input;w=int(i());n=int(i());d=list(range(w)) for j in range(n):a,b=map(int,i().split(','));d[a-1],d[b-1]=d[b-1],d[a-1] for i in d:print(i+1)
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s992475364
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s099036593
p00011
Accepted
# -*- coding: utf-8 -*- import sys def amida(w, side_bar): result = [] side_bar.reverse() for x in range(1, w+1): status = x for bar in side_bar: if status == bar[0]: status = bar[1] elif status == bar[1]: status = bar[0] result.append(status) return result def main(): W = int(input()) N = int(input()) side_bar = [tuple(map(int, input().split(','))) for line in range(N)] result = amida(W, side_bar) for r in result: print(r) if __name__ == '__main__': main()
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s650762525
p00011
Accepted
w = int(raw_input().rstrip()) l=[] for i in range(w+1): l.append(i) n = int(raw_input().rstrip()) for i in range(n): a, b = raw_input().rstrip().split(",") l[int(a)], l[int(b)] = l[int(b)], l[int(a)] for i in range(w): print l[i+1]
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s506039958
p00011
Accepted
w = int(input()) n = int(input()) ans = [i for i in range(w)] for i in range(n): a,b = list(map(int, input().split(","))) temp = ans[a-1] ans[a-1] = ans[b-1] ans[b-1] = temp for i in ans: print(i+1)
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s322661417
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 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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s119830844
p00011
Accepted
#!/usr/bin/env python # -*- coding:utf-8 -*- w = int(input()) n = int(input()) v_lines = [i for i in range(1,w+1)] for i in range(n): a,b = list(map(int, input().split(','))) t = v_lines[a-1] v_lines[a-1] = v_lines[b-1] v_lines[b-1] = t for i in range(len(v_lines)): print(v_lines[i])
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s720946282
p00011
Accepted
import sys import math as mas w=int(input()) n=int(input()) a=[i for i in range(1,w+1)] for i in range(n): b,c=map(int,input().split(',')) a[b-1],a[c-1]=a[c-1],a[b-1] for i in a:print(i) #for i in sys.stdin: # a,b=map(int,i.split()) # print(gcd(a,b),lcm(a,b))
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s294388964
p00011
Accepted
# -*- coding: utf-8 -*- import sys import os import math tate = int(input()) yoko = int(input()) values = [i for i in range(tate)] #print(values) for _ in range(yoko): a, b = map(int, input().split(',')) a -= 1 b -= 1 values[a], values[b] = values[b], values[a] for i in values: print(i+1)
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s214923094
p00011
Accepted
list = {} for a in range(1, int(input()) + 1) : list[a] = a for a in range(int(input())) : x, y = [int(temp) for temp in input().split(',')] temp = list[x] list[x] = list[y] list[y] = temp for a in range(1, len(list) + 1) : print(list[a])
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s001699690
p00011
Accepted
w = int(input()) n = int(input()) a = list(range(w)) for i in range(n): k1,k2 = map(int,input().split(",")) a[k1-1],a[k2-1] = a[k2-1],a[k1-1] for i in a: print(i+1)
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s865516057
p00011
Accepted
import sys num = input() list = {} for i in range(1, int(num) + 1): list[i] = i for i in range(int(input())) : x, y = map(int, input().split(',')) temp = list[x] list[x] = list[y] list[y] = temp for i in range(1, len(list) + 1): print(list[i])
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s498976759
p00011
Accepted
import sys lines = str(sys.stdin.read()).strip().split("\n") W = int(lines.pop(0)) N = int(lines.pop(0)) results = list(range(1,W + 1)) for i in range(N): data = list(map(lambda i: int(i) - 1, lines[i].split(","))) results[data[0]], results[data[1]] = results[data[1]], results[data[0]] for result in results: print(result)
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s350752310
p00011
Accepted
def main(): w = int(input()) n = int(input()) ans =[i for i in range(1, w+1)] def change(li, a, b): tmp = li[a-1] li[a-1] = li[b-1] li[b-1] = tmp return li for _ in range(n): a, b = map(int, input().split(",")) ans = change(ans, a, b) print(*ans, sep="\n") if __name__ == "__main__": main()
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s244965184
p00011
Accepted
import sys n = int(sys.stdin.readline().rstrip()) m = int(sys.stdin.readline().rstrip()) l = [] for i in range(m): l.append(list(map(int, sys.stdin.readline().rstrip().split(',')))) for i in range(n): cur = i+1 for d in l[::-1]: if cur in d: cur = d[0] if cur == d[1] else d[1] print(cur)
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s007462410
p00011
Accepted
w, n = int(input()), int(input()) p = list(range(1, w + 1)) l = [list(map(int, input().split(","))) for i in range(n)] for j in l: p[j[0] - 1], p[j[1] - 1] = p[j[1] - 1], p[j[0] - 1] k = [print(v) for v in p]
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s524576676
p00011
Accepted
#!/usr/bin/env python3 # -*- coding: utf-8 -*- def main(): w = int(input()) n = int(input()) xs = [i for i in range(w+1)] for _ in range(n): a, b = map(int, input().split(",")) xs[a], xs[b] = xs[b], xs[a] for i in range(1, w+1): print(xs[i]) if __name__ == "__main__": main()
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s660766099
p00011
Accepted
w = int(input()) n = int(input()) am = [i for i in range(w+1)] for _ in range(n): a, b = map(int, input().split(',')) am[a], am[b] = am[b], am[a] print(*am[1:], sep="\n")
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s654951900
p00011
Accepted
w = int(input()) nums = list(range(w + 1)) for _ in range(int(input())): a, b = map(int, input().split(",")) nums[a], nums[b] = nums[b], nums[a] for x in nums[1:]: print(x)
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s490784002
p00011
Accepted
w = int(input()) n = int(input()) a = [[int(i) for i in input().split(",")] for j in range(n)] b = [0 for i in range(w)] for i in range(1, w+1): next_num = i for j in a: if next_num == j[0]: next_num = j[1] elif next_num == j[1]: next_num = j[0] b[next_num - 1] = i for i in range(w): print(b[i])
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s217503761
p00011
Accepted
user = input() w = int(user) user = input() n = int(user) a = [] b = [] now = 0 for i in range(n): user = input() users = user.split(",") a.append(int(users[0])) b.append(int(users[1])) for j in range(1, w+1): now = j for k in reversed(range(n)): if now == a[k]: now = b[k] elif now == b[k]: now = a[k] print(now)
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s937530996
p00011
Accepted
# Aizu Problem 0011: Drawing Lots # import sys, math, os # read input: PYDEV = os.environ.get('PYDEV') if PYDEV=="True": sys.stdin = open("sample-input.txt", "rt") w = int(input()) slots = list(range(1, w + 1)) n = int(input()) for k in range(n): a, b = [int(_) for _ in input().split(',')] slots[a-1], slots[b-1] = slots[b-1], slots[a-1] for s in slots: print(s)
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s953927413
p00011
Accepted
w=int(input()) n=int(input()) a=[] b=[] Ans=[int(0) for i in range(w)] for i in range(n): x,y=[int(j) for j in input().split(",")] a.append(x) b.append(y) for i in range(1,w+1): ans=i for j in range(len(a)): if ans==a[j]: ans=b[j] elif ans==b[j]: ans=a[j] Ans[ans-1]=i for i in range(w): print(Ans[i])
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s201268156
p00011
Accepted
W = int(input()) N = int(input()) edges = [tuple(map(lambda c:int(c)-1, input().split(","))) for _ in [0]*N] result = list(range(1, W+1)) for a, b in edges: result[a], result[b] = result[b], result[a] print("\n".join(map(str, result)))
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s608882828
p00011
Accepted
import sys w = int(input()) n = int(input()) l = list() for _ in range(n): l.append(list(map(int,input().split(",")))) res = [0 for _ in range(w)] for i in range(1,w+1): tgt = i for num in l: if tgt in num: if num.index(tgt) == 1: tgt = num[0] else: tgt = num[1] res[tgt-1] = i for x in res: print(x)
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s074781986
p00011
Accepted
stick = [i for i in range(1, int(input()) + 1)] net = int(input()) for _ in range(net): a, b = list(map(int, input().split(","))) stick[a - 1], stick[b - 1] = stick[b - 1], stick[a - 1] for v in stick: print(v)
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s951031881
p00011
Accepted
if __name__ == '__main__': w = (int)(input()) n = (int)(input()) a = [i+1 for i in range(0,w)] for i in range(n): x,y = map(int,input().split(",")) a[x-1],a[y-1] = a[y-1],a[x-1] for x in a: print(x)
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s502585122
p00011
Accepted
w = int(input().rstrip()) n = int(input().rstrip()) amida = [i for i in range(w)] for i in range(n): a = input().rstrip().split(",") number = [int(i) - 1 for i in a] amida[number[0]], amida[number[1]] = amida[number[1]], amida[number[0]] for i in amida: print(i + 1)
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s653203354
p00011
Accepted
# coding=utf-8 def list_swap(given_list: list, swap_number1: int, swap_number2: int)-> list: return_list = given_list[:] memo = given_list[swap_number1 - 1] return_list[swap_number2 - 1] = memo memo = given_list[swap_number2 - 1] return_list[swap_number1 - 1] = memo return return_list if __name__ == '__main__': w = int(input()) amida_number = [i for i in range(1, w+1)] n = int(input()) for j in range(n): a, b = map(int, input().split(',')) amida_number = list_swap(amida_number[:], a, b) [print(amida_number[k]) for k in range(w)]
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s586449187
p00011
Accepted
# coding: utf-8 w = int(raw_input()) n = int(raw_input()) yoko = [] for i in range(n): data = map(int, raw_input().split(",")) yoko.append(data) ans = [] for i in range(1,w+1): ans.append(0) for num in range(1,w+1): # deb.printdebug1(num, debug) direction = num for c in yoko: if c[0] == direction: # deb.printdebug2(direction, debug) # deb.printdebug2(c[1], debug) direction = c[1] elif c[1] == direction: # deb.printdebug2(direction, debug) # deb.printdebug2(c[1], debug) direction = c[0] ans[direction-1] = num for i in ans: print(i)
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s722912010
p00011
Accepted
w = int(input()) n = int(input()) goal = [i for i in range(1,w+1)] for i in range(n): a,b = [int(j) for j in input().split(',')] goal[a-1],goal[b-1] = goal[b-1],goal[a-1] for po in goal: print(po)
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s049326605
p00011
Accepted
w = int(input()) lots = [i for i in range(w)] n = int(input()) for i in range(n): a, b = map(int, input().split(",")) lots[a - 1], lots[b - 1] = lots[b - 1], lots[a - 1] for i in range(w): print(lots[i] + 1)
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s980189990
p00011
Accepted
def main(): n = int(input()) point = int(input()) A = [] for i in range(n): A.append(i+1) for i in range(point): a,b = map(int,input().split(",")) A[a-1],A[b-1] = A[b-1],A[a-1] for value in A: print(value) if __name__ == '__main__': main()
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s426420518
p00011
Accepted
data = [] w = int(input()) for i in range(w): data.append(i+1) n = int(input()) for line in range(n): a, b = [int(i) for i in input().split(',')] data[a-1], data[b-1] = data[b-1], data[a-1] for d in data: print(d)
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s329355588
p00011
Accepted
a = list(map(lambda x: x+1, range(int(input())))) for _ in range(int(input())): m,n = map(lambda x: int(x)-1, input().split(',')) a[m], a[n] = a[n],a[m] for i in a: print(i)
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s506672657
p00011
Accepted
w = int(raw_input()) n = int(raw_input()) list = [] for i in range(1, w+1): list.append(i) #print list #print list[0] for j in range(1, n+1): num1, num2 = map(int, raw_input().split(",")) temp = list[num1-1] list[num1-1]=list[num2-1] list[num2-1]=temp #print temp for k in range(0, w): print list[k]
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s295373102
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 x in l: 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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s257798072
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s083203946
p00011
Accepted
w = int(input()) n = int(input()) amida = [] amida.append(-1) for i in range(w): amida.append(i) for l in range(n): a,b = [int(i) for i in input().split(",")] tmp = amida[a] amida[a] = amida[b] amida[b] = tmp for i in range(w): print(amida[i+1]+1)
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s141850550
p00011
Accepted
a=[i+1 for i in range(int(input()))] for _ in[0]*int(input()): s,t=map(lambda x:int(x)-1,input().split(',')) a[s],a[t]=a[t],a[s] print(*a,sep='\n')
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s137010476
p00011
Accepted
a=list(range(int(input())+1)) for _ in[0]*int(input()): s,t=map(int,input().split(','));a[s],a[t]=a[t],a[s] for s in a: if s:print(s)
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s289216499
p00011
Accepted
a=list(range(int(input())+1)) for _ in[0]*int(input()):s,t=map(int,input().split(','));a[s],a[t]=a[t],a[s] for s in a:s and print(s)
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s297051288
p00011
Accepted
tate =int(input()) yoko=int(input()) arr = [i+1 for i in range(tate)] for j in range(yoko): rep1,rep2=input().split(",") rep1=int(rep1)-1 rep2=int(rep2)-1 arr[rep1],arr[rep2] = arr[rep2],arr[rep1] for k in range(tate): print(arr[k])
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s419145572
p00011
Accepted
li = list(range(1, int(input())+1)) for i in range(int(input())): a,b=map(int, input().split(',')) li[a-1], li[b-1] = li[b-1], li[a-1] for i in li: print(i)
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s185116184
p00011
Accepted
# coding: utf-8 w = int(input()) ans = [i + 1 for i in range(w)] loop = int(input()) # swap for _ in range(loop): left, right = map(int, input().split(",")) ans[left-1], ans[right-1] = ans[right-1], ans[left-1] # result for i in ans: print(i)
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s915778118
p00011
Accepted
w=int(input()) l=[i+1 for i in range(w)] n=int(input()) for _ in range(n): a,b=[int(i)-1 for i in input().split(",")] t=l[a] l[a]=l[b] l[b]=t for i in l: print(i)
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s732508682
p00011
Accepted
w = int(input()) n = int(input()) lst = [i + 1 for i in range(w)] def swap(t): a,b = t temp = lst[a-1] lst[a-1] = lst[b-1] lst[b-1] = temp for i in range(n): swap(tuple(map(int,input().split(",")))) for i in range(w): print(lst[i])
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s341716171
p00011
Accepted
if __name__ == '__main__': w = int(input()) result = [i + 1 for i in range(w)] n = int(input()) permutations = [] for _ in range(n): permutations.append(map(lambda x: int(x) - 1, input().split(','))) for i, j in permutations: result[j], result[i] = result[i], result[j] print("\n".join(map(str, result)))
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s637805638
p00011
Accepted
a=list(range(int(input())+1)) for _ in[0]*int(input()):s,t=map(int,input().split(','));a[s],a[t]=a[t],a[s] [print(s)for s in a if s]
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s868386538
p00011
Accepted
w=int(input()) n=int(input()) d=[list(map(int,input().split(',')))for i in range(n)] 結果=[0]*w for j in range(w): 現在位置 = j + 1 for k1,k2 in d: if 現在位置==k1: 現在位置 = k2 elif 現在位置==k2: 現在位置=k1 結果[現在位置-1]=j+1 print(*結果,sep='\n')
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s909070834
p00011
Accepted
a = [i for i in range(int(input()) + 1)] for _ in range(int(input())): x, y = map(int, input().split(",")) a[x], a[y] = a[y], a[x] [print(e) for e in a[1:]]
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s518658475
p00011
Accepted
w=input() n=input() A=[ i+1 for i in range(w)] for i in range(n): a,b=map(int, raw_input().split(",")) ta=A[a-1] tb=A[b-1] A[a-1]=tb A[b-1]=ta for i in A: print i
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s832524089
p00011
Accepted
w = int(input()) n = int(input()) nums = [i for i in range(1, w+1)] ab = [] for i in range(n): a, b = map(int, input().split(',')) nums[a-1], nums[b-1] = nums[b-1], nums[a-1] for i in nums: print(i)
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s720879751
p00011
Accepted
w = int(input()) n = int(input()) amida = [] for i in range(0,w+1): amida.append(i) for i in range(n): ai,bi = map(int,input().split(",")) aa = amida[ai] bb = amida[bi] amida[ai] = bb amida[bi] = aa for i in range(1,w+1): print(amida[i])
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s596709118
p00011
Accepted
w=list(range(int(input()))) sw=[list(map(int,input().split(","))) for i in range(int(input()))] for i in sw: w[i[0]-1],w[i[1]-1]=w[i[1]-1],w[i[0]-1] [print(i+1) for i in w]
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s296685260
p00011
Accepted
w = int(input()) n = int(input()) amida = [i for i in range(1, w + 1)] for _ in range(n): a, b = list(map(int, input().split(','))) temp = amida[a - 1] amida[a - 1] = amida[b - 1] amida[b - 1] = temp for i in amida: print(i)
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s184866663
p00011
Accepted
# AOJ 0009 Prime Number # Python3 2018.6.9 bal4u w = int(input()) s = [i for i in range(w+1)] n = int(input()) for i in range(n): a = list(map(int, input().split(','))) s[a[0]], s[a[1]] = s[a[1]], s[a[0]] for i in range(1, w+1): print(s[i])
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s555763777
p00011
Accepted
arr = [i + 1 for i in range(int(input()))] m = int(input()) for i in range(m): inp = list(map(int, input().split(","))) tmp = arr[inp[0] - 1] arr[inp[0] - 1] = arr[inp[1] - 1] arr[inp[1] - 1] = tmp for i in range(len(arr)): print(arr[i])
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s308277300
p00011
Accepted
w = input() bar = range(w) n = input() p = 0 while p != n: rev = raw_input().split(',') bar[int(rev[0])-1],bar[int(rev[1])-1] = bar[int(rev[1])-1],bar[int(rev[0])-1] p += 1 for i in bar: print i+1
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s140509661
p00011
Accepted
import sys w = int(sys.stdin.readline()) n = int(sys.stdin.readline()) lines = list() for line in xrange(n): line = sys.stdin.readline() line = line.strip() lines.append(map(int, line.split(","))) def swap(yoko, nums): a, b = yoko a -= 1 b -= 1 tmp = nums[a] nums[a] = nums[b] nums[b] = tmp nums = range(1, w+1) for yoko in lines: swap(yoko, nums) for i in nums: print i
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s498555427
p00011
Accepted
list = [x+1 for x in xrange(int(input()))] tmp = 0 for i in xrange(int(input())): ch = [int(x) for x in raw_input().split(",")] tmp = list[ch[0]-1] list[ch[0]-1] = list[ch[1]-1] list[ch[1]-1] = tmp for x in list: print x
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s585259191
p00011
Accepted
w=input() list=range(0,w+1) n=input() for i in xrange(n): a,b=map(int,raw_input().split(',')) tmp=list[a] list[a]=list[b] list[b]=tmp for i in xrange(w): print list[i+1]
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s413050580
p00011
Accepted
w=input() list=range(0,w+1) n=input() for i in xrange(n): a,b=map(int,raw_input().split(',')) tmp=list[a] list[a]=list[b] list[b]=tmp for i in list[1:]: print i
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->
s617757894
p00011
Accepted
#coding: utf-8 while 1: try: v = input() h = input() n = range(1, v+1) for i in xrange(h): vl = map(int, raw_input().split(",")) n[vl[0]-1], n[vl[1]-1] = n[vl[1]-1], n[vl[0]-1] for i in xrange(v): print n[i] except EOFError: break
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> &le; 30) is the number of vertical lines. <var>n</var> (<var>n</var> &le; 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> -->