Pagini recente » Cod sursa (job #2811768) | Cod sursa (job #2087628) | Cod sursa (job #2885652) | Cod sursa (job #971041) | Cod sursa (job #2069210)
#include <bits/stdc++.h>
#define x first
#define y second
#define eps 1e-9
using namespace std;
ofstream fout ("dmin.out");
ifstream fin ("dmin.in");
queue < int > q;
priority_queue < pair < long double , int > > pq;
vector < pair < int , long double > > w[2000];
int viz[2000],parc[2000],n,m,a,b,aux1,crt,i,dp[2000],poz[2000];
long double c,rsp[2000];
pair < long double , int > aux;
void bfs()
{
viz[ 1 ] = 1;
parc[ ++crt ] = 1;
poz[ 1 ] = 1;
q.push( 1 );
while( q.size() )
{
aux1 = q.front();
q.pop();
for( auto it : w[ aux1 ] )
{
if( !viz[ it.x ] )
{
viz[ it.x ] = 1;
parc[ ++crt ] = it.x;
poz[ it.x ] = crt;
q.push( it.x );
}
}
}
memset( viz , 0 , sizeof( viz ) );
}
int main()
{
fin>>n>>m;
for( i = 1 ; i <= m ; i++ )
{
fin>>a>>b>>c;
c = log( c );
w[ a ].push_back( { b , c } );
w[ b ].push_back( { a , c } );
}
bfs();
pq.push( { 0.0 , 1 } );
while( pq.size() )
{
aux = pq.top();
pq.pop();
if( viz[ aux.y ] == 1 )
continue;
viz[ aux.y ] = 1;
rsp[ aux.y ] = -aux.x;
for( auto it : w[ aux.y ] )
if( !viz[ it.x ] )
pq.push( { aux.x - it.y , it.x } );
}
dp[ 1 ] = 1;
for( i = 2 ; i <= n ; i++ )
for( auto it : w[ parc[ i ] ] )
if( abs( rsp[ parc[ i ] ] - rsp[ it.x ] - it.y ) <= eps && poz[ parc[ i ] ] > poz[ parc[ it.x ] ] )
dp[ parc[ i ] ] += dp[ parc[ it.x ] ];
for( i = 2 ; i <= n ; i++ )
fout<<dp[ i ]<<" ";
}