20分玄关求调!
查看原帖
20分玄关求调!
1024387
xQWQx楼主2024/6/27 22:08

用的Floyd

#include <bits/stdc++.h>
using namespace std;
int dist[105][105];
int a[105];
int n,m,k;
void floyd(){
    for(int k=1;k<=n;k++){
        for(int i=1;i<=n;i++){
        if(dist[i][k]==0x3f3f3f3f || i==k) continue;
            for(int j=1;j<=n;j++){
                if(dist[k][j]==0x3f3f3f3f || j==k || i==j) continue;
                dist[i][j]=1;
            }
        }
    }
}
int main(){
    memset(dist,0x3f,sizeof(dist));
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        int u,v;
        cin>>u>>v;
        dist[u][v]=dist[v][u]=1;
    }
    int ans=0;
    for(int i=1;i<=n;i++){
        int cnt=0;
        for(int j=1;j<=n;j++){
            if(dist[i][j]!=0x3f3f3f3f&&i!=j){
                // cout<<i<<" "<<j<<endl;
                cnt++;
            }
            if(dist[j][i]!=0x3f3f3f3f&&i!=j){
                // cout<<i<<" "<<j<<endl;
                cnt++;
            }
            // if(dist[i][j]==0x3f3f3f3f)cout<<0<<" ";
            // else cout<<dist[i][j]<<" ";
        }
        // cout<<endl;
        // cout<<cnt<<endl;
        if(cnt>=n){
            // cout<<i<<endl;
            ans+=cnt/(n-1);
        } 
    }cout<<ans;
    return 0;
}

// 0 1 0 0 0 
// 1 0 1 1 1 
// 0 1 0 1 0 
// 0 1 1 0 0 
// 0 1 0 0 0 
2024/6/27 22:08
加载中...