CodeForces 1076D Edge Deletion(优化最短路)

Description

You are given an undirected connected weighted graph consisting of nvertices and m edges. Let's denote the length of the shortest path from vertex 1 to vertex i as di.

You have to erase some edges of the graph so that at most kedges remain. Let's call a vertex i good if there still exists a path from 1 to i with length di after erasing the edges.

Your goal is to erase the edges in such a way that the number of good vertices is maximized.

Input

The first line contains three integers n, m and k (2≤n≤3⋅105, 1≤m≤3⋅105, n−1≤m, 0≤k≤m) — the number of vertices and edges in the graph, and the maximum number of edges that can be retained in the graph, respectively.

Then m lines follow, each containing three integers x, y, w (1≤x,y≤n, x≠y, 1≤w≤109), denoting an edge connecting vertices x and y and having weight w.

The given graph is connected (any vertex can be reached from any other vertex) and simple (there are no self-loops, and for each unordered pair of vertices there exists at most one edge connecting these vertices).

Output

In the first line print e— the number of edges that should remain in the graph (0≤e≤k).

In the second line print edistinct integers from 1 to m— the indices of edges that should remain in the graph. Edges are numbered in the same order they are given in the input. The number of good vertices should be as large as possible.

Sample Input

Input

3 3 2
1 2 1
3 2 1
1 3 3

Output

2
1 2 

Input

4 5 2
4 1 8
2 4 1
2 1 3
3 4 9
3 1 5

Output

2
3 2 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#define eps 1e-10
#define mem(a) memset(a,0,sizeof(a))
#define maxx 1e10
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
struct A
{
    ll ed,w,num;
    ll x,y;
    bool operator < (const A & a) const
    {
        return w>a.w;
    }
};
priority_queue  q;
ll n,m,k;
vector a[300010];
set  ans;
ll vis[300010];
queue dis;
int main()
{
    cin>>n>>m>>k;
    for(ll i=1; i<=m; i++)
    {
        ll x,y,z;
        cin>>x>>y>>z;
        A t;
        t.ed=y;
        t.num=i;
        t.w=z;
        a[x].push_back(t);
        t.ed=x;
        t.num=i;
        t.w=z;
        a[y].push_back(t);
    }
    mem(vis);
    vis[1]=1;
    for(ll i=0; i::iterator it;
    for(it=ans.begin(); it!=ans.end(); it++)
    {
        if(!i)
            cout<<*it;
        else
            cout<<" "<<*it;
        i++;
    }
    cout<

 

 

你可能感兴趣的:(题目,图论)