Pagini recente » Cod sursa (job #1873293) | Cod sursa (job #593450) | Cod sursa (job #2176504) | Cod sursa (job #2821272) | Cod sursa (job #1399814)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
ifstream fin("Sate.txt");
ofstream fout("Sate.out");
struct nod
{
int i;
int j;
int D;
};
int main()
{
vector<nod> sate;
int x, y, m, n;
fin >> n;
fin >> m;
fin >> x;
fin >> y;
while (!fin.eof())
{
nod *p = new nod;
fin >> p->i;
fin >> p->j;
fin >> p->D;
sate.push_back(*p);
}
vector<nod>::const_iterator cii;
int sc = x;
int distanta = 0;
cii = sate.begin();
while (sc!=y)
{
if (sc == cii->i)
{
sc = cii->j;
distanta += cii->D;
}
else if (sc==cii->j)
{
sc = cii->i;
distanta -= cii->D;
}
cii++;
if (cii == sate.end())
cii = sate.begin();
}
fout << distanta;
return 1;
}