Cod sursa(job #967004)

Utilizator costin7856Antonesi Florean Costin costin7856 Data 26 iunie 2013 21:40:17
Problema Ubuntzei Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.77 kb
#include <fstream>

using namespace std;

ifstream f1("ubuntzei.in");
ofstream f2("ubuntzei.out");

int a[2000][2000],n,m,k,c;

void citeste()
{
    int i,j;
    f1>>n>>m;
    int c;
    f1>>k;
    if(k!=0)
    for(i=1;i<=k;i++)
        f1>>c;

    int x,y,z;
    for(i=1;i<=m;i++)
    {
        f1>>x>>y>>z;
        a[x][y]=z;
        a[y][x]=z;
    }
}

void solve()
{
    int i,j;
    for(int k = 1; k <= n; k++)
        for(i = 1; i <= n; i++)
            for(j = 1; j <= n; j++)
                if(a[i][k] && a[k][j] && i != j && (a[i][j] > a[i][k] + a[k][j] || !a[i][j]))
                    a[i][j] = a[i][k] + a[k][j];
    f2<<a[1][n];
}

int main()
{
    citeste();
    solve();

    f1.close();
    f2.close();
    return 0;
}