Edge Deletion CodeForces - 1076D

http://codeforces.com/contest/1076/problem/D

求单源最短路时保存一下路径 最后就是一棵树 然后bfs一遍即可

 

#include 
using namespace std;
#define pb push_back
typedef long long ll;
const int maxn=3e5+10;
const int maxm=3e5+10;

struct node1
{
    ll w;
    int id,v,next;
};

struct node2
{
    ll val;
    int id;
    bool friend operator < (node2 n1,node2 n2){
        return n1.val>n2.val;
    }
};

struct node3
{
    int id,v;
};

node1 edge[2*maxm];
priority_queue  que;
node3 pre[maxn];
vector  gou[maxn];
queue  queque;
ll dis[maxn];
int first[maxn],book[maxn],ans[maxm];
int n,m,k,num;

void addedge(int id,int u,int v,ll w)
{
    edge[num].id=id;
    edge[num].v=v;
    edge[num].w=w;
    edge[num].next=first[u];
    first[u]=num++;
}

void dijkstra()
{
    node2 tmp;
    ll w;
    int i,id,u,v;
    memset(dis,0x3f,sizeof(dis));
    dis[1]=0;
    tmp.val=0,tmp.id=1;
    que.push(tmp);
    while(!que.empty()){
        tmp=que.top();
        que.pop();
        u=tmp.id;
        if(book[u]) continue;
        book[u]=1;
        for(i=first[u];i!=-1;i=edge[i].next){
            id=edge[i].id,v=edge[i].v,w=edge[i].w;
            if(!book[v]&&dis[v]>dis[u]+w){
                pre[v].id=id,pre[v].v=u;
                dis[v]=dis[u]+w;
                tmp.val=dis[v],tmp.id=v;
                que.push(tmp);
            }
        }
    }
}

void bfs()
{
    int i,id,u,v;
    memset(book,0,sizeof(book));
    queque.push(1);
    book[1]=1;
    num=0;
    if(num==k) return;
    while(!queque.empty()){
        u=queque.front();
        queque.pop();
        for(i=0;i

 

你可能感兴趣的:(最短路)