Cod sursa(job #1709245)

Utilizator ubb_oprimabuzurile_2016UBB - OprimAbuzurile2016 - Petru Bianca Cosmin ubb_oprimabuzurile_2016 Data 28 mai 2016 11:27:06
Problema Politie Scor 100
Compilator cpp Status done
Runda ONIS 2016 - Runda - 2 - ACM ICPC Romanian Programming Contest Marime 0.87 kb
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <set>
#define LL long long
#define x first
#define y second
#define mp make_pair
#define DN 250005
using namespace std;

typedef pair<int,int> per;

int n,m,d,p,pre[DN];
vector<pair<per,per> > muc;
set<int> s;

int fnd(int x) {
  if(pre[x]==x) return x;
  pre[x]=fnd(pre[x]);
  return pre[x];
}

void un(int x,int y) {
  pre[fnd(x)]=fnd(y);
}

int main() {
  //ifstream f("input.txt");
  ifstream f("politie.in");
  ofstream g("politie.out");
  for(f>>n>>m>>d>>p;m--;) {
    int x,y,t,c; f>>x>>y>>t>>c;
    muc.push_back(mp(mp(t,c),mp(x,y)));
  }
  sort(muc.begin(),muc.end());
  for(int i=1; i<=n; ++i) pre[i]=i;
  for(auto i:muc) if(fnd(i.y.x)!=fnd(i.y.y)) {
    s.insert(-i.x.y);
    un(i.y.x,i.y.y);
  }
  set<int>::iterator is=s.begin();
  for(int i=0; i<p; ++i,++is) {
    g<<-(*is)<<'\n';
  }
}