Pagini recente » Cod sursa (job #3180573) | Cod sursa (job #763316) | Cod sursa (job #52924) | Cod sursa (job #448845) | Cod sursa (job #922634)
Cod sursa(job #922634)
#include<fstream>
#include<algorithm>
#include<queue>
#include<vector>
#define maxn 50010
const int inf = 0x3f3f3f3f;
using namespace std;
struct muchie{
int y,c,d;
};
vector<muchie> e[maxn];
bool test[maxn];
queue<int> Q;
int D,N,M;
int nrD;
long d[maxn];
ifstream f("gather.in");
ofstream g("gather.out");
int bellman(int S){
for(int i=1;i<=N;i++)
d[i]=inf;
d[S]=0;
Q.push(S);
while(!Q.empty()){
int nod=Q.front();
Q.pop();
test[nod]=false;
for(vector< muchie >::iterator it=e[nod].begin();it!=e[nod].end();++it){
if(d[it->y]>d[nod]+it->c&&nrD<=it->d){
d[it->y]=d[nod]+(nrD+1)*it->c;
Q.push(it->y);
if(test[it->y]){
nrD++;
if(nrD==D)
return d[it->y];
}
}
}
}
return 0;
}
void citire(){
muchie m;
int x,y;
f>>D>>N>>M;
for(int i=0;i<D;i++){
f>>x;
test[x]=true;
}
for(int i=1;i<=M;i++){
f>>x>>y>>m.c>>m.d;
m.y=y;
e[x].push_back(m);
m.y=x;
e[y].push_back(m);
}
}
int main(){
citire();
g<<bellman(1);
/*for(int i=2;i<=N;i++)
if(d[i]==inf)
g<<0<<' ';
else
g<<d[i]<<' ';
*/
g<<'\n';
g.close();
return 0;
}