Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct no {
- int v, qtd;
- no() {}
- no(int v, int qtd) : v(v), qtd(qtd) {}
- bool operator < (const no &outro) const {
- return qtd > outro.qtd;
- }
- };
- vector<int> g[maxn];
- int atiradores[maxn];
- int dijkstra(int s, int t) {
- int qtd[maxn]; memset(qtd, inf, sizeof qtd);
- priority_queue<no> pq;
- pq.push(no(s, atiradores[s]));
- qtd[s] = atiradores[s];
- while (!pq.empty()) {
- no tmp = pq.top(); pq.pop();
- int u = tmp.v;
- if (u == t) return qtd[u];
- for (int i = 0; i < g[u].size(); i++) {
- int v = g[u][i];
- if (qtd[v] > qtd[u] + atiradores[v]) {
- qtd[v] = qtd[u] + atiradores[v];
- pq.push(no(v, qtd[v]));
- }
- }
- }
- return inf;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement