CF1941D.Rudolf and the Ball Game
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
The first line of the input contains a single integer t ( 1≤t≤104 ) — the number of test cases. Then follow the descriptions of the test cases.
The first line of each test case contains three integers n,m,x ( 2≤n≤1000 , 1≤m≤1000 , 1≤x≤n ) — the number of players, the number of throws made, and the number of the player who threw the ball first, respectively.
The next m lines contain information about each throw in order. Each of them contains an integer ri ( 1≤ri≤n−1 ) — the distance at which the i -th throw was made, and a symbol ci , equal to '0', '1', or '?':
- if ci ='0', then the i -th throw was made clockwise,
- if ci ='1', then the i -th throw was made counterclockwise,
- if ci ='?', then Bernard does not remember the direction and the i -th throw could have been made either clockwise or counterclockwise.
It is guaranteed that the sum n⋅m ( n multiplied by m ) over all test cases does not exceed 2⋅105 .
输入格式
For each test case, output two lines.
In the first line, output the number of players k ( 1≤k≤n ) who could have the ball at the end of the game.
In the next line, output k numbers bi ( 1≤bi≤n ) — the numbers of the players in increasing order. All numbers must be different.
输出格式
Below is an illustration of three throws for the first test case. The arrows denote possible throw directions. Players who could have the ball after the throw are highlighted in gray.
输入输出样例
输入#1
5 6 3 2 2 ? 2 ? 2 ? 12 1 2 3 1 10 7 4 2 ? 9 1 4 ? 7 0 2 0 8 1 5 ? 5 3 1 4 0 4 ? 1 ? 4 1 1 2 ?
输出#1
3 2 4 6 1 11 4 3 5 7 9 3 2 3 5 1 3
说明/提示
Below is an illustration of three throws for the first test case. The arrows denote possible throw directions. Players who could have the ball after the throw are highlighted in gray.