zoukankan      html  css  js  c++  java
  • POJ 1125

    很简单的题,不过题面信息冗余,要快速抽取信息

    快速复习了一边Floyd算法

    #include <iostream>
    #include <algorithm>
    #include <queue>
    #include <string>
    #include <vector>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <string>
    #include <stack>
    #include <map>
    #include <set>
    using namespace std;
    
    const int maxn= 105;
    const int INF= 0x3f3f3f3f;
    
    int dv[maxn][maxn];
    
    int main(int argc, char const *argv[])
    {
    	int n;
    	while (~scanf("%d", &n) && n){
    		memset(dv, 0x3f, sizeof(dv));
    		for (int i= 1; i<= n; ++i){
    			int m, p, v;
    			scanf("%d", &m);
    			for (int j= 1; j<= m; ++j){
    				scanf("%d %d", &p, &v);
    				dv[i][p]= v;
    			}
    			dv[i][i]= 0;
    		}
    
    		for (int r= 1; r<= n; ++r){
    			for (int i= 1; i<= n; ++i){
    				for (int j= 1; j<= n; ++j){
    					dv[i][j]= min(dv[i][j], dv[i][r]+dv[r][j]);
    				}
    			}
    		}
    
    		int minc= INF, stoc= -1;
    		for (int i= 1; i<= n; ++i){
    			int t_min= 0, flag= 1;
    			for (int j= 1; j<= n; ++j){
    				if (INF== dv[i][j]){
    					flag= 0;
    					break;
    				}
    				t_min= max(t_min, dv[i][j]);
    			}
    			if (flag && t_min< minc){
    				minc= t_min;
    				stoc= i;
    			}
    		}
    
    		if (-1== stoc){
    			printf("disjoint
    ");
    		}
    		else{
    			printf("%d %d
    ", stoc, minc);
    		}
    	}
    	return 0;
    }
    
  • 相关阅读:
    Spark SQL+day04笔记
    Spark 环境搭建
    海量数据处理 算法总结2
    Scala面试题 看过1
    HTML-table、form表单标签的介绍
    Java-CSS美化网页元素
    Java-BOM与DOM对象
    java-CSS盒子模型、浮动、定位
    java-基础面试题(2)
    Java-io流
  • 原文地址:https://www.cnblogs.com/Idi0t-N3/p/14694406.html
Copyright © 2011-2022 走看看