From dcc3671eb2978a3a69b351cbe584c45877f323d0 Mon Sep 17 00:00:00 2001 From: userr2232 Date: Sat, 20 Mar 2021 16:19:30 -0500 Subject: [PATCH] UVa/10461 --- UVa/10461.cc | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 UVa/10461.cc diff --git a/UVa/10461.cc b/UVa/10461.cc new file mode 100644 index 0000000..0b8d1e7 --- /dev/null +++ b/UVa/10461.cc @@ -0,0 +1,59 @@ +#include +#include +#include +#include +#include +#include + +using namespace std; + +int main() { + int v, e, c{1}; + while(cin >> v >> e, e || v) { + int x, y; + vector task_time(v + 1, 0); + map> ancestors; + map> 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; + } +} \ No newline at end of file