Cod sursa(job #131813)

Utilizator andrei.12Andrei Parvu andrei.12 Data 4 februarie 2008 15:10:05
Problema PScNv Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.14 kb
#include<stdio.h>
#include<vector>
#include<algorithm>

using namespace std;

#define lg 250005

vector<int> v[lg], vc[lg], cuoada[1005];
int n, m, np, nf, x, y, cst, i, j, k, nod, maxcost, nr[lg], nrp[1005], d[lg];
int main()
{
	freopen("pscnv.in", "rt", stdin);
	freopen("pscnv.out", "wt", stdout);
	
	scanf("%d%d%d%d", &n, &m, &np, &nf);
	for (i = 1; i <= m; i ++){
		scanf("%d%d%d", &x, &y, &cst);
		
		if (x != y){
			nr[x] ++;
			v[x].push_back(y);
			vc[x].push_back(cst);
			
			maxcost = max(maxcost, cst);
		}
	}
	
	nrp[0] = 1;
	cuoada[0].push_back(np);
	d[np] = -1;
	for (i = 0; i <= maxcost; i ++)
		for (j = 0; j < nrp[i]; j ++){
			x = cuoada[i][j];
			if (x == nf){
				printf("%d\n", i);
				return 0;
			}
			if (d[x] == i)
				for (k = 0; k < nr[x]; k ++){
					nod = v[x][k];
					cst = vc[x][k];
					
					if (cst < i){
						nrp[i] ++;
						cuoada[i].push_back(nod);
						if (d[nod] == 0 || d[nod] > i)
							d[nod] = i;
					}
					else{
						nrp[cst] ++;
						cuoada[cst].push_back(nod);
						if (d[nod] == 0 || d[nod] > cst)
							d[nod] = cst;
					}
				}
		}
	
	return 69;
}