Mai intai trebuie sa te autentifici.
Cod sursa(job #2118480)
| Utilizator | Data | 30 ianuarie 2018 18:08:14 | |
|---|---|---|---|
| Problema | Sate | Scor | 80 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.81 kb |
#include <bits/stdc++.h>
using namespace std;
vector<pair<long long, long long> > a[31000];
bool viz[31000];
long long rez[31000], n, m, x, y;
void dfs(long long x, long long c)
{
rez[x] = c;
viz[x] = 1;
for (long long i = 0; i < a[x].size(); i++)
if (!viz[a[x][i].first])
dfs(a[x][i].first, x < a[x][i].first ? c + a[x][i].second : c - a[x][i].second);
}
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ifstream cin("sate.in");
ofstream cout("sate.out");
cin >> n >> m >> x >> y;
for (long long i = 0; i < m; i++)
{
long long x, y, z;
cin >> x >> y >> z;
a[y].push_back(make_pair(x,z));
a[x].push_back(make_pair(y,z));
}
dfs(x, 0);
cout << rez[y];
return 0;
}
