Pagini recente » Cod sursa (job #1080509) | Cod sursa (job #3131759) | Cod sursa (job #1934209) | Cod sursa (job #760804) | Cod sursa (job #1884600)
#include <fstream>
#include <queue>
#include <cstring>
#include <vector>
using namespace std;
ifstream fin("pitici.in");
ofstream fout("pitici.out");
vector <pair <int,int> > G[1024];
int N,M,K;
bool Use[1024];
int Cost[1024],DP[1024][1024],Index[1024];
const int INF = 0x3f3f3f3f;
void Read()
{
fin>>N>>M>>K;
for(int i=1;i<=M;i++)
{
int x,y,c;
fin>>x>>y>>c;
G[x].push_back(make_pair(y,c));
}
}
struct Compare{
bool operator()(const int a,const int b)const{
return Cost[a]>Cost[b];
}
};
void DFS(int node)
{
Use[node]=1;
if(node==N)
{
DP[N][0]=0;
return;
}
if(G[node].size()==0)
return;
priority_queue <int,vector<int>,Compare> Heap;
for(int i=0;i<G[node].size();i++)
{
int neighb=G[node][i].first,cost=G[node][i].second;
if(Use[neighb]==0)
DFS(neighb);
Cost[neighb]=DP[neighb][0]+cost;Index[neighb]=0;
Heap.push(neighb);
}
for(int i=0;i<K;i++)
{
int neighb=Heap.top();
Heap.pop();
DP[node][i]=Cost[neighb];
Cost[neighb]-=DP[neighb][Index[neighb]];
++Index[neighb];
Cost[neighb]+=DP[neighb][Index[neighb]];
Heap.push(neighb);
}
}
int main()
{
Read();
memset(DP,INF,sizeof(DP));
DFS(1);
for(int i=0;i<K;i++)
fout<<DP[1][i]<<" ";
fout<<"\n";
return 0;
}