HZNU Training 23 for Zhejiang Provincial Competition 2020

Posted littlerita

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HZNU Training 23 for Zhejiang Provincial Competition 2020相关的知识,希望对你有一定的参考价值。

 拓扑排序,从上往下回溯,挺好奇差分约束为啥就不对。拓扑排序有明显的优先级。

技术图片技术图片
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
typedef long long ll;
const int inf=0x3f3f3f3f;
typedef long long ll;
typedef double db;
const int N=1e4+50;
vector<int>e[N];
int n,m;
int in[N],a[N];
int topo(){
    int cnt=0;
    queue<int>Q;
    for(int i=1;i<=n;i++)if(in[i]==0)cnt++,Q.push(i);
    while(!Q.empty()){
        int u=Q.front();Q.pop();
        for(int i=0;i<e[u].size();i++){
            int v=e[u][i];--in[v];
            if(!in[v]){
                Q.push(v),cnt++;
                a[v]=max(a[v],a[u]+1);

            }
        }
    }
    if(cnt<n)return -1;
    int sum=0;
    for(int i=1;i<=n;i++)sum+=888+a[i];
    return sum;
}
int main(){

    while(~scanf("%d %d",&n,&m)){
    memset(in,0,sizeof in);
    memset(a,0,sizeof a);
    for(int i=1;i<=n;i++)e[i].clear();
    for(int i=1,u,v;i<=m;i++){
        scanf("%d %d",&u,&v);
        e[v].pb(u);in[u]++;
    }    
    cout<<topo()<<endl;
    }
    // system("pause");
    return 0;
}
View Code

G - G

 HDU - 3635 

带权并查集

 

以上是关于HZNU Training 23 for Zhejiang Provincial Competition 2020的主要内容,如果未能解决你的问题,请参考以下文章

HZNU Training 2 for Zhejiang Provincial Competition 2020

HZNU 2019 Summer training 4

HZNU 2019 Summer training 6

HZNU 2019 Summer training 8

HZNU 2019 Summer training 6 -CodeForces - 622

hznu