Pagini recente » Cod sursa (job #2488003) | Cod sursa (job #3011) | Cod sursa (job #1118438) | Cod sursa (job #292876) | Cod sursa (job #1391343)
#include <iostream>
#include <fstream>
#include <queue>
#include <stack>
#include <vector>
using namespace std;
int mat[20000][20000];
int n, viz[20000], numar, m, lant;
void bf(int start, int end )
{
int j, x, dist = 0;
queue < int > c;
c.push( start );
viz[ start ] = 1;
while ( !c.empty() )
{
x = c.front();
c.pop();
for ( j = 1; j <= n; j++ )
if( mat[ x ][ j ] && !viz[ j ] )
{
c.push( j );
viz[ j ] = 1;
if ( x < j )
dist += mat[ x ][ j ];
else
dist -= mat[ x ] [ j ];
if ( j == end )
goto loop1;
}
}
return;
loop1:
ofstream g("sate.out");
g << dist;
//cout<< dist;
}
int main()
{
ifstream f( "sate.in" );
int i, j, k, lung, x, y;
f >> n >> m;
f >> x >> y;
for ( i = 1; i <= m ; i++ )
{
f >> j >> k >> lung;
mat[ j ] [ k ] = mat[ k ][ j ] = lung;
}
f.close();
bf( x, y );
return 0;
}