Skip to content

Commit

Permalink
UVa/10461
Browse files Browse the repository at this point in the history
  • Loading branch information
userr2232 committed Jul 27, 2021
1 parent 9bef399 commit dcc3671
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions UVa/10461.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#include <iostream>
#include <set>
#include <vector>
#include <algorithm>
#include <iterator>
#include <map>

using namespace std;

int main() {
int v, e, c{1};
while(cin >> v >> e, e || v) {
int x, y;
vector<long long> task_time(v + 1, 0);
map<int,set<int>> ancestors;
map<int,set<int>> descendants;
for(int i = 1; i <= v; ++i)
cin >> task_time[i];
for(int i = 0; i < e; ++i) {
cin >> x >> y;
ancestors[x].insert(y);
descendants[y].insert(x);
for(auto a: ancestors[y]) {
for(auto d : descendants[x]) {
descendants[a].insert(d);
descendants[a].insert(x);
descendants[y].insert(d);
ancestors[d].insert(a);
ancestors[x].insert(a);
ancestors[d].insert(y);
}
}
for(auto d : descendants[x]) {
ancestors[d].insert(y);
descendants[y].insert(d);
}
for(auto a : ancestors[y]) {
descendants[a].insert(x);
ancestors[x].insert(a);
}
}
int q;
cin >> q;
cout << "Case #" << c++ << ":" << endl;
while(q--) {
long long sum{0}, qn;
cin >> qn;
for(int i = 1; i <= v; ++i) {
if(!ancestors[qn].count(i) && !descendants[qn].count(i) && i != qn) {
sum += task_time[i];
// cout << i << endl;
}
}
cout << sum << endl;
// if(qn == 90) return 0;
}
cout << endl;
}
}

0 comments on commit dcc3671

Please sign in to comment.