Pagini recente » Cod sursa (job #349197) | Cod sursa (job #83227) | Cod sursa (job #1477996) | Cod sursa (job #329133) | Cod sursa (job #1709406)
#include <iostream>
#include <vector>
#include <fstream>
#include <algorithm>
using namespace std;
ifstream fin("politie.in");
ofstream fout("politie.out");
int getInt();
/// //////////////////////////////////
#define mmax 500010
#define cout fout
int ind[mmax],dad[250010];
struct
{
int x,y,cat,per;
} muc[mmax];
int n,m,D,P;
vector<int> ind_res;
void read()
{
n=getInt();
m=getInt();
D=getInt();
P=getInt();
for(int i=1; i<=m; ++i)
{
muc[i].x=getInt();
muc[i].y=getInt();
muc[i].cat=getInt();
muc[i].per=getInt();
ind[i]=i;
}
}
inline int get_dad(int nod)
{
if(nod!=dad[nod]) dad[nod]=get_dad(dad[nod]);
return dad[nod];
}
bool cmp_first(int a,int b)
{
if(muc[a].cat!=muc[b].cat) return muc[a].cat<muc[b].cat;
return muc[a].per<muc[b].per;
}
bool cmp_res(int a,int b)
{
return muc[a].per>muc[b].per;
}
int main()
{
read();
sort(ind+1,ind+m+1,cmp_first);
int i;
for(i=1; i<=n; ++i) dad[i]=i;
for(i=1; i<=m; ++i)
{
if(get_dad(muc[ind[i]].x)!=get_dad(muc[ind[i]].y))
{
ind_res.push_back(ind[i]);
dad[dad[muc[ind[i]].x]]=muc[ind[i]].y;
}
}
sort(ind_res.begin(),ind_res.end(),cmp_res);
cout<<muc[ind_res[0]].per<<'\n';
int cnt;
for(i=1,cnt=1; cnt<P; ++i)
{
if(muc[ind_res[i]].per!=muc[ind_res[i-1]].per)
{
++cnt;
cout<<muc[ind_res[i]].per<<'\n';
}
}
}
unsigned const maxb = 666013;
unsigned ptr = maxb - 1;
char buf[maxb];
int getInt()
{
int rez = 0;
while(!(buf[ptr] >= '0' && buf[ptr] <= '9'))
{
if(++ptr >= maxb)
{
fin.read(buf, maxb);
ptr = 0;
}
}
while((buf[ptr] >= '0' && buf[ptr] <= '9'))
{
rez = rez * 10 + buf[ptr] - '0';
if(++ptr >= maxb)
{
fin.read(buf, maxb);
ptr = 0;
}
}
return rez;
}