Pagini recente » Cod sursa (job #668861) | Cod sursa (job #2058510) | Cod sursa (job #514838) | Cod sursa (job #2134755) | Cod sursa (job #1938278)
#include <bits/stdc++.h>
using namespace std;
ifstream f("pitici.in");
ofstream g("pitici.out");
int n,m,k,i,j,a,b,c,x,P[1<<10],L[1<<10],C[1<<10];
bool viz[1<<10];
vector<int> S[1<<10],G[1<<10];
vector<pair<int,int> > R[1<<10];
multiset<pair<int,int> > H;
void dfs(int x)
{
viz[x]=1;
for(int i=0;i<G[x].size();++i)
if(!viz[G[x][i]]) dfs(G[x][i]);
P[++P[0]]=x;
}
int main()
{
f>>n>>m>>k;
while(m--)
{
f>>a>>b>>c;
G[a].push_back(b);
R[b].push_back(make_pair(a,c));
}
dfs(1);
S[1].push_back(0);
for(i=n-1;i;--i)
{
H.clear();
x=P[i];
for(j=0;j<R[x].size();++j)
{
L[R[x][j].first]=0;
C[R[x][j].first]=R[x][j].second;
H.insert(make_pair(S[R[x][j].first][0]+R[x][j].second,R[x][j].first));
}
while(S[x].size()<k&&!H.empty())
{
pair<int,int> now=*H.begin();
H.erase(H.begin());
S[x].push_back(now.first);
if(++L[now.second]<S[now.second].size())
H.insert(make_pair(S[now.second][L[now.second]]+C[now.second],now.second));
}
}
for(i=0;i<k;++i) g<<S[n][i]<<' ';
return 0;
}