Pagini recente » Cod sursa (job #195067) | Cod sursa (job #140777) | Clasament fmi-no-stress-9-warmup | Cod sursa (job #3249299) | Cod sursa (job #373410)
Cod sursa(job #373410)
#include<cstdio>
#define N 1020
#define M 200020
#include<vector>
#include<algorithm>
#define pb push_back
using namespace std;
vector<short int> a[N];
//vector<bool> viz[N];
int c[N][N],cost[N][N],m;
short int n,k;
bool b[N];
inline void citire()
{
freopen("pitici.in","r",stdin);
freopen("pitici.out","w",stdout);
scanf("%hd%d%hd",&n,&m,&k);
for (int i=1; i<=m; ++i)
{
short int x,y,cost;
scanf("%hd%hd%hd",&x,&y,&cost);
a[y].pb(x);
c[y][x]=cost;
}
}
short int coada[M];
int p,u,x,y;
void bfs()
{
coada[u++]=n;
cost[n][0]=1;
while (u!=p)
{
x=coada[p++];
if (cost[x][0]>k)
{
sort(cost[x]+1,cost[x]+1+cost[x][0]);
cost[x][0]=k;
}
size_t g=a[x].size();
for (size_t i=0; i<g; ++i)
{
y=a[x][i];
if (!b[y])
{
coada[u++]=y;
b[y]=true;
}
for (int j=1; j<=cost[x][0]; ++j)
cost[y][++cost[y][0]]=cost[x][j]+c[x][y];
}
}
//sort (cost[1]+1,cost[1]+1+cost[1][0]);
}
inline void afis()
{
for(int i=1; i<=k; ++i)
printf("%d ",cost[1][i]);
}
int main()
{
citire();
bfs();
afis();
return 0;
}