// 4 3 1 1 100 // 0 1 Q // 1 2 Q // 2 3 Q // 3 1 #include using namespace std; const long long INF = 100000007; long long sum = 0; class OFFICE; class LINK { public: OFFICE* X; bool type; // 0-> Optic; 1-> Quantum int len = 0; }; class OFFICE { public: vector connections{}; long long dist = INF; }; vector graph; void Dijkstra(int start, int start_distance) { priority_queue > q; // weight, node q.push(make_pair(start_distance, &graph[start])); while(!q.empty()) { pair current = q.top(); q.pop(); for(int i = 0; i < current.second->connections.size(); i++) { OFFICE* node = current.second->connections[i].X; int dl = current.second->connections[i].len; if(node->dist > current.second->dist + dl) { node->dist = current.second->dist + dl; q.push(make_pair(node->dist, node)); } } } } bool cmp(pair x, pair y) { if(x.first.X != y.first.X) return x.first.X > y.first.X; else return x.second == 'T'; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int number_of_ex_office, cables_btw_existing, new_requests, toptic, tquantum; cin >> number_of_ex_office >> cables_btw_existing >> new_requests >> toptic >> tquantum; for(int i = 0; i < number_of_ex_office; i++) { OFFICE x; x.dist = INF; x.connections = {}; graph.push_back(x); } for(int i = 0; i < cables_btw_existing; i++) { LINK x; int a, b; char c; cin >> a >> b >> c; x.X = &graph[a]; if(c == 'O') {x.type = 0; x.len = toptic;} else {x.type = 1; x.len = tquantum;} graph[b].connections.push_back(x); x.X = &graph[b]; graph[a].connections.push_back(x); } graph[0].dist = 0; Dijkstra(0, 0); for(int i = 0; i < graph.size(); i++) {if(graph[i].dist != INF) sum += graph[i].dist;} // for(int i = 0; i < number_of_ex_office; i++) // { // cout << i << ": \ndist-> " << graph[i].dist <> Trequest >> Srequest; vector > all; for(int i = 0; i < graph[Trequest].connections.size(); i++) all.push_back(make_pair(graph[Trequest].connections[i], 'T')); for(int i = 0; i < graph[Srequest].connections.size(); i++) all.push_back(make_pair(graph[Srequest].connections[i], 'S')); sort(all.begin(), all.end(), cmp); // for(int i = 0; i < all.size(); i++) cout << all[i].first.X << " " << all[i].first.type << all[i].second < y.X->dist + y.len) min_len = y.X->dist + y.len; } } else //single agent connection { if(all[i].second == 'T') { x.connections.push_back(all[i].first); if(min_len > all[i].first.X->dist + all[i].first.len) min_len = all[i].first.X->dist + all[i].first.len; } else { LINK y; y.type = !all[i].first.type; if(y.type) y.len = tquantum; else y.len = toptic; y.X = all[i].first.X; x.connections.push_back(y); if(min_len > y.X->dist + y.len) min_len = y.X->dist + y.len; } } } if(i != all.size()) { if(all[i].second == 'T') { x.connections.push_back(all[i].first); if(min_len > all[i].first.X->dist + all[i].first.len) min_len = all[i].first.X->dist + all[i].first.len; } else { LINK y; y.type = !all[i].first.type; if(y.type) y.len = tquantum; else y.len = toptic; y.X = all[i].first.X; x.connections.push_back(y); if(min_len > y.X->dist + y.len) min_len = y.X->dist + y.len; } } // cout << min_len <