zoukankan      html  css  js  c++  java
  • 【SDOI2010】大陆争霸

    题面

    https://www.luogu.org/problem/P2446

    题解

    // luogu-judger-enable-o2
    #include<cstdio>
    #include<iostream>
    #include<cstring>
    #include<vector>
    #include<queue>
    #define LL long long
    #define ri register int
    #define N 3050
    using namespace std;
    
    int n,m;
    vector<int> to[N],len[N];
    vector<int> fa[N];
    LL dis[N],d[N];
    bool vis[N];
    int cnt[N],tot[N];
    
    
    void add_edge(int z,int y,int x) {
      to[z].push_back(y); len[z].push_back(x);
    }
    
    struct node {
      int x; LL d;
      bool operator < (const node &rhs) const {
        return d>rhs.d;
      }
    };
    priority_queue<node> q;
    
    LL dij() {
      memset(dis,0x3f,sizeof(dis));
      dis[1]=0;
      q.push((node){1,0});
      while (!q.empty()) {
        int x=q.top().x; q.pop();
        if (vis[x]) continue;
        vis[x]=1;
        for (ri i=0;i<fa[x].size();i++) {
          dis[fa[x][i]]=max(dis[x],dis[fa[x][i]]);
          cnt[fa[x][i]]++;
          if (cnt[fa[x][i]]==tot[fa[x][i]]) {
            q.push((node){fa[x][i],dis[fa[x][i]]});
          }
        }
        for (ri i=0;i<to[x].size();i++) {
          int y=to[x][i];
          if (dis[y]>dis[x]+len[x][i]) {
            dis[y]=dis[x]+len[x][i];
            if (cnt[y]==tot[y]) q.push((node){y,dis[y]});
          }
        }
      }
      return dis[n];
    }
    
    int main() {
      int a,b,c;
      scanf("%d %d",&n,&m);
      for (ri i=1;i<=m;i++) {
        scanf("%d %d %d",&a,&b,&c);
        add_edge(a,b,c);
      }
      for (ri i=1;i<=n;i++) {
        scanf("%d",&tot[i]);
        for (ri j=1;j<=tot[i];j++) {
          scanf("%d",&b);
          fa[b].push_back(i);
        }
      }
      cout<<dij()<<endl;
    }
  • 相关阅读:
    mobile app 的总结
    ie和火狐javascript区别
    zepto源码注释
    ie6bug
    html5游戏网站
    jquery作者封装函数
    vue element 动态表格
    uniapp 对 系统的控制,全屏,系统虚拟键盘,手机导航,强制横屏
    环形图表记录
    清除所有的滚动条
  • 原文地址:https://www.cnblogs.com/shxnb666/p/11278437.html
Copyright © 2011-2022 走看看