poj 2394
#include<iostream>
#include<fstream>
#include<queue>
using namespace std;
int f,p,c,m;
struct e{
int data;
int cost;
e *next;
};
e edge[501];
void add(int s,int t,int w){
e *p=new e;
p->data=t;
p->cost=w;
p->next=edge[s].next;
edge[s].next=p;
e *q=new e;
q->data=s;
q->cost=w;
q->next=edge[t].next;
edge[t].next=q;
}
struct node{
int data;
int weight;
friend bool operator <(node a,node b){
return a.weight>b.weight;
}
};
int d[501];
int v[501];
int cc[501];
void solve(){
int i,j,k;
for(i=1;i<=f;i++)
d[i]=1000000;
d[1]=0;
node a;
a.data=1;
a.weight=0;
priority_queue<node> q;
q.push(a);
while(!q.empty())
{
a=q.top();
q.pop();
if(v[a.data]) continue;
v[a.data]=1;
e *p=edge[a.data].next;
while(p)
{
if(d[p->data]>a.weight+p->cost)
{
d[p->data]=a.weight+p->cost;
node b;
b.data=p->data;
b.weight=d[p->data];
q.push(b);
}
p=p->next;
}
}
memset(v,0,sizeof(v));
j=0;
for(i=1;i<=c;i++)
if(d[cc[i]]<=m)
{
j++;
v[i]=1;
}
cout<<j<<endl;
for(i=1;i<=c;i++)
if(v[i])
cout<<i<<endl;
}
void read(){
// ifstream cin("in.txt");
int i,j,k,s,t,w;
cin>>f>>p>>c>>m;
for(i=1;i<=p;i++)
{
cin>>s>>t>>w;
add(s,t,w);
}
for(i=1;i<=c;i++)
cin>>cc[i];
solve();
}
int main(){
read();
return 0;
}
#include<fstream>
#include<queue>
using namespace std;
int f,p,c,m;
struct e{
int data;
int cost;
e *next;
};
e edge[501];
void add(int s,int t,int w){
e *p=new e;
p->data=t;
p->cost=w;
p->next=edge[s].next;
edge[s].next=p;
e *q=new e;
q->data=s;
q->cost=w;
q->next=edge[t].next;
edge[t].next=q;
}
struct node{
int data;
int weight;
friend bool operator <(node a,node b){
return a.weight>b.weight;
}
};
int d[501];
int v[501];
int cc[501];
void solve(){
int i,j,k;
for(i=1;i<=f;i++)
d[i]=1000000;
d[1]=0;
node a;
a.data=1;
a.weight=0;
priority_queue<node> q;
q.push(a);
while(!q.empty())
{
a=q.top();
q.pop();
if(v[a.data]) continue;
v[a.data]=1;
e *p=edge[a.data].next;
while(p)
{
if(d[p->data]>a.weight+p->cost)
{
d[p->data]=a.weight+p->cost;
node b;
b.data=p->data;
b.weight=d[p->data];
q.push(b);
}
p=p->next;
}
}
memset(v,0,sizeof(v));
j=0;
for(i=1;i<=c;i++)
if(d[cc[i]]<=m)
{
j++;
v[i]=1;
}
cout<<j<<endl;
for(i=1;i<=c;i++)
if(v[i])
cout<<i<<endl;
}
void read(){
// ifstream cin("in.txt");
int i,j,k,s,t,w;
cin>>f>>p>>c>>m;
for(i=1;i<=p;i++)
{
cin>>s>>t>>w;
add(s,t,w);
}
for(i=1;i<=c;i++)
cin>>cc[i];
solve();
}
int main(){
read();
return 0;
}