Pagini recente » Cod sursa (job #1632931) | Cod sursa (job #277379) | Cod sursa (job #700758) | Cod sursa (job #214228) | Cod sursa (job #2702311)
#include <bits/stdc++.h>
#define ll long long
#define sz(x) (int)(x).size()
#define debug(v,n) for (int i = 1; i <= (n); ++i) cout << v[i] << " ";
#define next cout << '\n'
using namespace std;
const int N = 30005;
vector<pair<int,int>> graf[N];
int n, m, x, y;
struct cmp {
bool operator()(int a, int b) {
return sz(graf[a]) > sz(graf[b]);
}
};
priority_queue<int, vector<int>, cmp> coada;
int main() {
//ifstream fin("date.in.txt");
ifstream fin("sate.in");
ofstream fout("sate.out");
fin >> n >> m >> x >> y;
for (int i = 1; i <= m; ++i) {
int a, b, d;
fin >> a >> b >> d;
graf[a].push_back({b, d});
graf[b].push_back({a, d});
}
for (int i = x; i <= y; ++i)
coada.push(i);
while(!coada.empty()) {
int nod = coada.top();
coada.pop();
/*
*/
for (int i = 0; i < sz(graf[nod]); ++i) {
int act = graf[nod][i].first, lgAct = graf[nod][i].second;
for (int j = i + 1; j < sz(graf[nod]); ++j) {
int to = graf[nod][j].first, lg = graf[nod][j].second;
if(to > act) {
graf[act].push_back({to, lg + lgAct});
graf[to].push_back({act, lg + lgAct});
}
else {
graf[to].push_back({act, lg - lgAct});
graf[act].push_back({to, lg - lgAct});
}
}
}
}
for (int i = 0; i < sz(graf[x]); ++i) {
if(graf[x][i].first == y) {
fout << graf[x][i].second;
return 0;
}
}
return 0;
}