Pagini recente » Cod sursa (job #3248797) | Cod sursa (job #709441) | Cod sursa (job #542061) | Cod sursa (job #883256) | Cod sursa (job #1703895)
# include <fstream>
# include <vector>
# define DIM 1029
# define a first.first
# define b first.second
# define c second.first
# define d second.second
# define f first
# define s second
using namespace std;
ifstream fin("pitici.in");
ofstream fout("pitici.out");
pair <pair<int,int>,pair<int,int> > h[DIM],aux;
vector <pair<int,int> > Lista[DIM];
vector <int> drum[DIM];
int Marcat[DIM],bun[DIM],r,n,m,i,j,x,y,z,t,k,p;
void add(int x,int y,int z,int t){
h[++r].a=x;
h[r].b=y;
h[r].c=z;
h[r].d=t;
int p=r/2,c1=r;
while(p!=0){
if(h[p].a>h[c1].a){
swap(h[c1],h[p]);
c1=p;
p/=2;
}
else
break;
}
}
void off(){
if(h[1].b+1<drum[h[1].c].size()){
aux.b=h[1].b+1;
aux.c=h[1].c;
aux.d=h[1].d;
aux.a=drum[aux.c][aux.b];
h[1]=aux;
}
else
h[1]=h[r--];
int p=1,c1=2;
while(c1<=r){
if(h[c1]>h[c1+1]&&c1+1<=r)
c1++;
if(h[p].a>h[c1].a){
swap(h[c1],h[p]);
p=c1;
c1*=2;
}
else
break;
}
}
void dfs(int nc){
Marcat[nc]=1;
int nv;
for(int i=0;i<Lista[nc].size();i++){
nv=Lista[nc][i].f;
if(Marcat[nv]==0)
dfs(nv);
}
r=0;
for(i=0;i<Lista[nc].size();i++){
nv=Lista[nc][i].f;
if(bun[nv]){
add(drum[nv][0],0,nv,Lista[nc][i].s);
bun[nc]=1;
}
}
p=0;
if(nc==n){
drum[nc].push_back(0);
bun[n]=1;
}
else
while(r!=0&&p<k){
p++;
drum[nc].push_back(h[1].a+h[1].d);
off();
}
}
int main () {
fin>>n>>m>>k;
for(i=1;i<=m;i++){
fin>>x>>y>>z;
Lista[x].push_back(make_pair(y,z));
}
dfs(1);
for(i=0;i<k;i++)
fout<<drum[1][i]<<" ";
fout<<"\n";
return 0;
}