fork download
  1. #include <map>
  2. #include <set>
  3. #include <cmath>
  4. #include <ctime>
  5. #include <deque>
  6. #include <queue>
  7. #include <stack>
  8. #include <bitset>
  9. #include <cctype>
  10. #include <cstdio>
  11. #include <vector>
  12. #include <cassert>
  13. #include <complex>
  14. #include <cstdlib>
  15. #include <cstring>
  16. #include <fstream>
  17. #include <iomanip>
  18. #include <sstream>
  19. #include <iostream>
  20. #include <algorithm>
  21.  
  22. using namespace std;
  23.  
  24. #define mp make_pair
  25. #define pb push_back
  26. #define ll long long
  27. #define fi first
  28. #define se second
  29.  
  30. #define all(a) a.begin(),a.end()
  31. #define fill(a,v) memset(a,v,sizeof(a))
  32.  
  33. #define bitcount __buitin_popcount
  34. #define gcd __gcd
  35.  
  36.  
  37. typedef vector<int> vi;
  38. typedef pair<int,int> pii;
  39. typedef vector<vi > vvi;
  40.  
  41. map<pii,int> visited;
  42. map<pii,vector<pii> > adj;
  43.  
  44. void dfs(pii src)
  45. {
  46.  
  47. visited[src] = 1;
  48. for(int i = 0 ; i < adj[src].size() ; ++i)
  49. if(!visited[adj[src][i]]) dfs(adj[src][i]);
  50. }
  51. int main()
  52. {
  53.  
  54.  
  55. long long n;
  56. while(cin >> n)
  57. {
  58. if(n == -1) return 0;
  59.  
  60. int q;
  61. cin >> q;
  62. pii query[q];string parity[q];
  63. adj.clear();
  64. for(int i = 0 ; i < q ; ++i)
  65. {
  66. int x,y;string par;
  67. cin >> x >> y >> par;
  68. query[i].fi = x;query[i].se = y; parity[i] = par;
  69. }
  70.  
  71. int cnt = 0;
  72. for(int i = 0 ; i < q ; ++i)
  73. {
  74. int x = query[i].fi;
  75. int y = query[i].se;
  76. pii t = mp(x-1,0),t1 = mp(x-1,1),d = mp(y,0),d1 = mp(y,1);
  77.  
  78. if(parity[i] == "even")
  79. {
  80.  
  81. adj[t1].pb(d1);
  82. adj[d1].pb(t1);
  83. adj[d].pb(t);
  84. adj[t].pb(d);
  85. }
  86. else if(parity[i] == "odd")
  87. {
  88. adj[t].pb(d1);
  89. adj[d1].pb(t);
  90. adj[t1].pb(d);
  91. adj[d].pb(t1);
  92. }
  93. visited.clear();
  94. dfs(mp(x-1,1));
  95. if(visited[mp(x-1,1)] == 1 && visited[mp(x-1,0)] == 1) goto p;
  96.  
  97. visited.clear();
  98. dfs(mp(y,0));
  99. if(visited[mp(y,0)] == 1 && visited[mp(y,1)] == 1) goto p;
  100.  
  101. cnt++;
  102. }
  103.  
  104.  
  105. p : cout << cnt << endl;
  106. }
  107.  
  108. }
  109.  
  110.  
  111.  
  112.  
Success #stdin #stdout 0s 3348KB
stdin
Standard input is empty
stdout
Standard output is empty