Cod sursa(job #2020520)

Utilizator PajarajaPavle Martinovic Pajaraja Data 10 septembrie 2017 16:22:33
Problema Lazy Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1 kb
#include <bits/stdc++.h>
using namespace std;
#define pii pair< pair < long long , long long > , pair < int , int > >
vector<pii > g[200001];
bool vi[200001];
void prim(int s)
{
	priority_queue<pii> h;
	pii x;
	vi[s]=true;
	for(int i=0;i<g[s].size(); i++)
	{
		x=g[s][i];
		h.push(x);
	}
	while(!h.empty())
	{
		x=h.top();
		h.pop();
		if(vi[x.second.first]) continue;
		printf("%d\n",x.second.second);
		s=x.second.first;
		vi[s]=true;
		for(int i=0;i<g[s].size(); i++)
	    {
		    x=g[s][i];
		    h.push(x);
		}
	}
}
int main()
{
	freopen("lazy.in","r",stdin);
	freopen("lazy.out","w",stdout);
	int n,m,t1,t2;
	long long t3,t4;
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++)
	{
		pii x;
		scanf("%d %d %lld %lld",&t1,&t2,&t3,&t4);
        x.first.first=-t3;
		x.first.second=t4;
		x.second.first=t2;
		x.second.second=i;
        x.first.first=-t3;
		x.first.second=t4;
		x.second.first=t1;
		x.second.second=i;
		g[t2].push_back(x);
	}
	prim(1);
	fclose(stdout);
}