Pagini recente » Cod sursa (job #2456107) | Cod sursa (job #827539) | Cod sursa (job #3209927) | Cod sursa (job #3251191) | Cod sursa (job #1438906)
#include <iostream>
#include<fstream>
#include<vector>
using namespace std;
vector <pair<int,int> > v[110000];
int n,m,x,y,viz[30001],dis[30001];
ifstream f("sate.in");
ofstream g("sate.out");
void parcurgere(int nod)
{
cout<<nod<<" ";
viz[nod]=1;
for(int i=0;i<v[nod].size();i++)
{
if(viz[v[nod][i].first]==0)
{
if(nod<v[nod][i].second)
dis[v[nod][i].first]=dis[nod]+v[nod][i].second;
else
dis[v[nod][i].first]=dis[nod]-v[nod][i].second;
if(v[nod][i].first==y) return;
else parcurgere(v[nod][i].first);
}
}
}
int main()
{
f>>n>>m>>x>>y;
for(int k=1;k<=n;k++)
{
int i,j,d;
f>>i>>j>>d;
v[i].push_back(make_pair(j,d));
v[j].push_back(make_pair(i,d));
}
parcurgere(x);//plec din x
g<<dis[y];
f.close();
g.close();
}