Pagini recente » Istoria paginii utilizator/mateasamuel | Cod sursa (job #2053614) | Istoria paginii utilizator/patroesculuiza | Cod sursa (job #1608047) | Cod sursa (job #878418)
Cod sursa(job #878418)
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
bool stop = false;
long dresult;
long long d[30001] = {0};
//vector< vector<short int> > val(30001, vector<short int>(30001));
short int val[30001][30001];
int n;
void get(int x, int dc, int v) {
if(v==x) {dresult=dc;stop=true;}
if(stop) return;
while(d[x]!=0) {
int y = d[x]%(n+1);
int value = val[x][y];
if(x>y) value *= -1;
int dcp = dc;
dcp += value;
d[x] /= n+1;
get(y, dcp, v);
}
}
int main() {
int m,x,y;
ifstream fin("sate.in");
ofstream fout("sate.out");
fin>>n>>m>>x>>y;
for(int i=1;i<=m;i++) {
int x0,y0,d0;
fin>>x0>>y0>>d0;
val[x0][y0]=d0;
d[x0]*=n+1;
d[x0]+=y0;
val[y0][x0]=d0;
d[y0]*=n+1;
d[y0]+=x0;
}
dresult=0;
get(x,0,y);
fout<<dresult;
return 0;
}