首页 > 代码库 > 1090. Highways
1090. Highways
#include "iostream" #include "memory.h" #include "cstdio" using namespace std; int grap[500][500]; int ans; int dis[500]; bool visited[500]; void prime(int n){ int source = 1; for (int i = 1; i <= n; i++){ dis[i] = grap[source][i]; visited[i] = false; } visited[source] = true; for (int j = 1; j < n; j++){ int min =65535; int index = 0; for (int i = 1; i <= n; i++){ if (!visited[i] && dis[i] < min){ min = dis[i]; index = i; } } visited[index] = true; if (ans < min) ans = min; for (int i = 1; i <= n; i++){ if(!visited[i] && (grap[index][i]) < dis[i]){ dis[i] = grap[index][i]; } } } } int main(){ int n; bool ok = false; int t; cin >> t; while ( t--){ if (ok) cout << endl; ok = true; cin >> n; if (n < 3){ cout << "\n"; continue; } ans = -1000; for (int i = 1; i <= n; i++){ for (int j = 1; j <= n; j++){ cin >> grap[i][j]; grap[j][i] = grap[i][j]; } } prime(n); cout << ans << endl; } }
1090. Highways
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。