码迷,mamicode.com
首页 > 其他好文 > 详细

Luogu1099 树网的核 (暴力?,floyd?)(还未想正解,暴力就A了)

时间:2019-07-27 12:44:39      阅读:74      评论:0      收藏:0      [点我收藏+]

标签:clu   atp   names   print   this   out   efi   using   ||   

阅读理解两小时,手敲暴力思考5分钟。然后\(n^3\)就A了
暴力代码

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#define R(a,b,c) for(register int  a = (b); a <= (c); ++ a)
#define nR(a,b,c) for(register int  a = (b); a >= (c); -- a)
#define Max(a,b) ((a) > (b) ? (a) : (b))
#define Min(a,b) ((a) < (b) ? (a) : (b))
#define Fill(a,b) memset(a, b, sizeof(a))
#define Abs(a) ((a) < 0 ? -(a) : (a))
#define Swap(a,b) a^=b^=a^=b
#define ll long long

#define ON_DEBUG

#ifdef ON_DEBUG

#define D_e_Line printf("\n\n----------\n\n")
#define D_e(x)  cout << #x << " = " << x << endl
#define Pause() system("pause")
#define FileOpen() freopen("in.txt","r",stdin);

#else

#define D_e_Line ;
#define D_e(x)  ;
#define Pause() ;
#define FileOpen() ;

#endif

struct ios{
    template<typename ATP>ios& operator >> (ATP &x){
        x = 0; int f = 1; char c;
        for(c = getchar(); c < '0' || c > '9'; c = getchar()) if(c == '-')  f = -1;
        while(c >= '0' && c <= '9') x = x * 10 + (c ^ '0'), c = getchar();
        x*= f;
        return *this;
    }
}io;
using namespace std;

const int N = 307;

int dis[N][N], D[N];
int vis[N];
int main(){
//FileOpen();
    int n, S;
    io >> n >> S;
    R(i,1,n){
        R(j,1,n){
            if(i != j)
                dis[i][j] = 2147483647;
        }
    }
    R(i,2,n){
        int u, v, w;
        io >> u >> v >> w;
        dis[u][v] = dis[v][u] =  w;
    }
    
    int DIS = 0;
    R(k,1,n){
        R(i,1,n){
            if(dis[i][k] == 2147483647) continue;
            R(j,1,n){
                if(dis[k][j] == 2147483647) continue;
                dis[i][j] = Min(dis[i][j], dis[i][k] + dis[k][j]);
                DIS = Max(DIS, dis[i][j]);
            }
        }
    }
    
    R(i,1,n){
        R(j,1,n){
            if(dis[i][j] == DIS){
                R(k,1,n){
                    if(dis[i][k] + dis[k][j] == dis[i][j]){
                        vis[k] = true;
                    }
                }
            }
        }
    }
    
    int ans = 2147483647;
    R(i,1,n){
        R(j,i,n){
            if(vis[i] && vis[j] && dis[i][j] <= S){
                R(xx,1,n) D[xx] = 2147483647;
                R(k,1,n){
                    if(dis[i][k] + dis[k][j] == dis[i][j]){
                        R(l,1,n){
                            D[l] = Min(D[l], dis[k][l]);
                        }
                    }
                }
                
                int maxx = 0;
                R(k,1,n){
                    maxx = Max(maxx, D[k]);
                }
                ans = Min(ans, maxx);
            }
        }
    }
    
    printf("%d", ans);
    
    return 0;
}

Luogu1099 树网的核 (暴力?,floyd?)(还未想正解,暴力就A了)

标签:clu   atp   names   print   this   out   efi   using   ||   

原文地址:https://www.cnblogs.com/bingoyes/p/11254395.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!