Pagini recente » Cod sursa (job #1086435) | Cod sursa (job #2948898) | Cod sursa (job #1186165) | Cod sursa (job #2951808) | Cod sursa (job #3291258)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("sate.in");
ofstream fout("sate.out");
int n, m, x, y, dist[100030], viz[100030];
vector<pair<int, int>> mat[30005];
void bfs(int x)
{
int nodcrt;
queue<int>q;
q.push(x);
viz[x]=1;
dist[x]=0;
while(!q.empty())
{
for(auto i:mat[nodcrt])
if(viz[i.first]==0)
{
viz[i.first]=1;
if(i.first>nodcrt)
dist[i.first]=dist[nodcrt]+i.second;
else
dist[i.first]=dist[nodcrt]-i.second;
}
}
}
int main()
{
int x,y,c;
while(fin>>x>>y>>c)
{
mat[x].push_back({y,c});
mat[y].push_back({x,c});
}
bfs(x);
fout<<dist[y];
return 0;
}