Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- #define int int64_t
- using namespace std;
- int n, m, k, a, b;
- map<int, set<int>> party;
- map<int, vector<pair<int, bool>>> test;
- vector<int> tmi;
- void infect(int x, int tm){
- if(tmi[x] != -1)
- return;
- tmi[x] = tm;
- for(int cur_tm = tm + a; cur_tm < tm + b; cur_tm++)
- if(party[cur_tm].find(x) != party[cur_tm].end())
- for(auto i: party[cur_tm])
- infect(i, cur_tm);
- }
- int check(int cur, int tm){
- for(int i = 0; i < n; i++)
- tmi[i] = -1;
- infect(cur, tm);
- int ans = 0;
- for(int i = 0; i < n; i++)
- for(auto j: test[i])
- if(j.first > tmi[i] && j.first < tmi[i] + b)
- if(j.second == 1)
- ans++;
- else
- if(j.second == 0)
- ans++;
- return ans;
- }
- int32_t main(){
- freopen("output.txt", "w", stdout);
- int t;
- cin >> t;
- while(t--){
- cin >> n >> m >> k >> a >> b;
- party.clear();
- test.clear();
- tmi.resize(n);
- while(m--){
- int tm, v;
- cin >> tm >> v;
- set<int> visitors;
- while(v--){
- int x;
- cin >> x;
- x--;
- visitors.insert(x);
- }
- party[tm] = visitors;
- }
- while(k--){
- pair<int, int> idf;
- bool res;
- cin >> idf.first >> idf.second >> res;
- idf.second--;
- test[idf.second].emplace_back(idf.first, res);
- }
- int who = 0, when = 1;
- for(int cur = 0; cur < n; cur++)
- for(int tm = 1; tm <= 10000; tm++)
- if(check(who, when) < check(cur, tm))
- who = cur, when = tm;
- cout << who + 1 << ' ' << when << '\n';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment