Pagini recente » Cod sursa (job #300853) | Cod sursa (job #1802368) | Cod sursa (job #932798) | Cod sursa (job #2037167) | Cod sursa (job #532482)
Cod sursa(job #532482)
#include<fstream>
#include<vector>
using namespace std;
ifstream fin("traseu.in");
ofstream fout("traseu.out");
int n, m;
int a[100][100];
int lung[100];
void Read();
void DF( int x, int sum );
int main()
{
Read();
DF(1, 0);
fin.close();
fout.close();
return 0;
}
void Read()
{
fin >> n >> m;
int x, y, c;
while( fin >> x >> y >> c )
{
a[x][y] = c;
lung[x] = lung[x]+1;
}
/*
for( int i = 1; i <= n; ++i )
{
fout << i << ": ";
for( int j = 1; j <= n; ++j )
if( a[i][j] != 0 )
fout << "(" << j << ", " << a[i][j] << ") ";
else
fout << " * ";
fout << '\n';
}
*/
}
void DF( int x, int sum )
{
if( lung[x] == 0 )
{
fout << sum;
exit(0);
}
for( int j = 1; j <= n; ++j )
if( a[x][j] != 0 )
{
if( j == 1 && x != 1 )
{
lung[x] = lung[x] - 1;
int k = a[x][j];
a[x][j] = 0;
DF( j, sum+k);
}
/*
if( lung[j] == 1 )
{
int k = a[x][j];
a[x][j] = 0;
lung[x] = lung[x] - 1;
DF( j, sum+k );
}
*/
DF( j, sum + a[x][j] );
}
}