fork download
  1. #include <bits/stdc++.h> // 🤷
  2. using namespace std;
  3. #define int long long
  4. #define all(v) v.begin(), v.end()
  5. #define rall(v) v.rbegin(),v.rend()
  6. #define pq_min priority_queue<int, vector<int>, greater<int>>
  7. #define C(x,y) ((x+y-1)/y)
  8. #define yes "YES\n"
  9. #define no "NO\n"
  10. typedef long long ll;
  11. typedef long double ld;
  12. const int dx[]={0,0,1,-1};
  13. const int dy[]={1,-1,0,0};
  14. const ld PI = 3.14159265358979323846;
  15. const int MOD = 1e9 + 7;
  16. const ll OO = 2e15;
  17. const int oo = 1e9;
  18. const int sz = 2e5+5;
  19. const ld eps = 1e-9;
  20. ///////////////////////////////////////////////////////////////////////////////////////
  21. int n,m,x; set<int>ans; queue<pair<int,char>>edges;
  22. void BFS(int s=x) {
  23. queue<int> q;
  24. q.push(s);
  25. while (!edges.empty()) {
  26. int d= edges.front().first; char c= edges.front().second;
  27. edges.pop();
  28. while (!q.empty()) {
  29. int cur = q.front();
  30. ans.insert(cur);
  31. q.pop();
  32. if (c=='0') {
  33. q.push(cur+d);
  34. }
  35. else if (c=='1') {
  36. q.push((cur-d+n)%n);
  37. }
  38. else {
  39. q.push(cur+d);
  40. q.push((cur-d+n)%n);
  41. }
  42. }
  43. }
  44. }
  45. //////////////////////////////////////////////////////////////////////////////////////
  46. void _3OMDA() {
  47. cin >> n>> m>>x;
  48. cin>>n>>m;
  49. for (int i=0;i<m;i++) {
  50. int d; cin >> d;
  51. char c; cin >> c;
  52. edges.push({d,c});
  53. }
  54. BFS();
  55. cout << ans.size()<<endl;
  56. for (auto i:ans) {
  57. cout << i << ' ';
  58. }
  59. cout<<endl;
  60. }
  61. //////////////////////////////////////////////////////////////////////////////////////
  62. signed main() {
  63. ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  64. //freopen("input.txt", "r", stdin);
  65. //freopen("output.txt", "w", stdout);
  66. int t = 1;
  67. // cin >> t;
  68. for (int i = 0; i < t; i++) {
  69. _3OMDA();
  70. }
  71. return 0;
  72. }
Success #stdin #stdout 0s 544KB
stdin
Standard input is empty
stdout
0