Cod sursa(job #639049)

Utilizator Tucu94Andrei Tuculanu Tucu94 Data 22 noiembrie 2011 11:07:39
Problema Sate Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.79 kb
#include<fstream>
using namespace std;

int C[30001],W[30001],viz[30001],L[30001],p,u,x,y,X,Y,a,M,N,i,d;
struct nod {
	int ve,di;
	nod *adr;
}*A[30001]; 
ifstream f("sate.in");
ofstream g("sate.out");

void citire(){
	f>>N>>M;
	f>>X>>Y;
	
	for(int i=1;i<=M;i++)
	{	
		f>>x>>y>>d;
		
		nod*p=new nod;
		p->ve=y;
		p->di=d;
		p->adr=A[x];
		A[x]=p;
		nod*q=new nod;
		q->ve=x;
		q->di=d;
		q->adr=A[y];
		A[y]=q;
	}

}
int main (){
	citire();
	
	
	C[1]=X;viz[X] = 1;
	for( p=1 , u=1; u>=p && C[p]!=Y ;p++)
	{
		for (nod*q = A[C[p]]; q!=NULL ; q=q->adr ) { 
			a = q->ve;
			d = q->di;
 			if (!viz[a]) {
				viz[a]=1;
				C[++u] = a;
				if(C[p]<a)
					W[a]=W[C[p]]+d;
				else
					W[a]=W[C[p]]-d;
			}
	
	
		}
	} 




	g<<W[Y];




return 0;
}