ProgMe

Untitled

Feb 22nd, 2021
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #define int int64_t
  3.  
  4. using namespace std;
  5.  
  6. int n, m, k, a, b;
  7. map<int, set<int>> party;
  8. map<int, vector<pair<int, bool>>> test;
  9. vector<int> tmi;
  10.  
  11. void infect(int x, int tm){
  12. if(tmi[x] != -1)
  13. return;
  14. tmi[x] = tm;
  15. for(int cur_tm = tm + a; cur_tm < tm + b; cur_tm++)
  16. if(party[cur_tm].find(x) != party[cur_tm].end())
  17. for(auto i: party[cur_tm])
  18. infect(i, cur_tm);
  19. }
  20.  
  21. int check(int cur, int tm){
  22. for(int i = 0; i < n; i++)
  23. tmi[i] = -1;
  24. infect(cur, tm);
  25. int ans = 0;
  26. for(int i = 0; i < n; i++)
  27. for(auto j: test[i])
  28. if(j.first > tmi[i] && j.first < tmi[i] + b)
  29. if(j.second == 1)
  30. ans++;
  31. else
  32. if(j.second == 0)
  33. ans++;
  34. return ans;
  35. }
  36.  
  37. int32_t main(){
  38. freopen("output.txt", "w", stdout);
  39. int t;
  40. cin >> t;
  41. while(t--){
  42. cin >> n >> m >> k >> a >> b;
  43. party.clear();
  44. test.clear();
  45. tmi.resize(n);
  46. while(m--){
  47. int tm, v;
  48. cin >> tm >> v;
  49. set<int> visitors;
  50. while(v--){
  51. int x;
  52. cin >> x;
  53. x--;
  54. visitors.insert(x);
  55. }
  56. party[tm] = visitors;
  57. }
  58. while(k--){
  59. pair<int, int> idf;
  60. bool res;
  61. cin >> idf.first >> idf.second >> res;
  62. idf.second--;
  63. test[idf.second].emplace_back(idf.first, res);
  64. }
  65. int who = 0, when = 1;
  66. for(int cur = 0; cur < n; cur++)
  67. for(int tm = 1; tm <= 10000; tm++)
  68. if(check(who, when) < check(cur, tm))
  69. who = cur, when = tm;
  70. cout << who + 1 << ' ' << when << '\n';
  71. }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment