-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontacttracing.cpp
82 lines (73 loc) · 1.8 KB
/
contacttracing.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#include <iostream>
#include <sstream>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include<tuple>
#include <unordered_set>
#include <unordered_map>
#include <set>
#include <map>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef tuple<ll, ll, ll> e;
vector<vi> AL;
priority_queue<e, vector<e>, greater<e>> EL;
vector<ll> visited;
set<ll> infected;
queue<ll> q;
set<ll> room;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//freopen("contact.in","r",stdin);
ll n, d; cin >> n >> d;
ll c; cin >> c;
AL.assign(n+1, vi());
visited.assign(n+1, 0);
while (c--) {
ll i; cin >> i;
infected.insert(i);
q.emplace(i); visited[i] = 1; //??
}
for (ll i=1; i<=n; i++) {
ll a, b; cin >> a >> b;
EL.emplace(make_tuple(a,0,i));
EL.emplace(make_tuple(b,1,i));
}
while (!EL.empty()) {
auto [_,c,i] = EL.top(); EL.pop();
if (c == 0) { //arrive
auto t = room.begin();
while (t != room.end()) {
AL[*t].push_back(i);
AL[i].push_back(*t);
t++;
}
room.emplace(i);
} else { //leave
room.erase(i);
}
}
ll count = q.size();
while (!q.empty()) {
ll curr = q.front(); q.pop(); count--;
for (auto& x:AL[curr]) {
if (!visited[x]) {
visited[x] = 1; q.emplace(x); infected.emplace(x);
}
}
if (count == 0) {
d--; count = q.size();
}
if (d == 0) break;
}
auto pr = infected.begin();
while (pr != infected.end()) {
cout << *pr << " "; pr++;
}
}