Pagini recente » Cod sursa (job #2276671) | Cod sursa (job #1330151) | Cod sursa (job #1885218) | Cod sursa (job #324470) | Cod sursa (job #2020462)
#include <bits/stdc++.h>
using namespace std;
#define pii pair< pair < long long , long long > , pair < int , int > >
vector<int> g[200001],w1[200001],w2[200001],ind[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.first.first=-w1[s][i];
x.first.second=w2[s][i];
x.second.first=g[s][i];
x.second.second=ind[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,x.second.first);
s=x.second.first;
vi[s]=true;
for(int i=0;i<g[s].size(); i++)
{
x.first.first=-w1[s][i];
x.first.second=w2[s][i];
x.second.first=g[s][i];
x.second.second=ind[s][i];
h.push(x);
}
}
}
int main()
{
fill(vi,vi+200001,false);
freopen("lazy.in","r",stdin);
freopen("lazy.out","w",stdout);
int n,m,t1,t2,t3,t4;
scanf("%d%d",&n,&m);
for(int i=1;i<=m;i++)
{
scanf("%d%d%lld%lld",&t1,&t2,&t3,&t4);
g[t1].push_back(t2);
w1[t1].push_back(t3);
w2[t1].push_back(t4);
ind[t1].push_back(i);
g[t2].push_back(t1);
w1[t2].push_back(t3);
w2[t2].push_back(t4);
ind[t2].push_back(i);
}
prim(1);
fclose(stdout);
}