标签:cap esc triple bitset set pat expand ted eth
Input
Output
Sample Input
1
3 3
1 2 3
1 3 4
2 3 5
Sample Output
Scenario #1: 4
和POJ2253那道题的青蛙跳反着来就可以了
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <deque>
#include <bitset>
//#include <unordered_set>
//#include <unordered_map>
//#include <bits/stdc++.h>
//#include <xfunctional>
#define ll long long
#define PII pair<int, int>
using namespace std;
int dir[5][2] = { { 0,1 } ,{ 0,-1 },{ 1,0 },{ -1,0 } ,{ 0,0 } };
const long long INF = 0x7f7f7f7f7f7f7f7f;
const int inf = 0x3f3f3f3f;
const double pi = 3.14159265358979;
const int mod = 1e9 + 7;
const int N = 1005;
//if(x<0 || x>=r || y<0 || y>=c)
//1000000000000000000
inline ll read()
{
ll x = 0; bool f = true; char c = getchar();
while (c < ‘0‘ || c > ‘9‘) { if (c == ‘-‘) f = false; c = getchar(); }
while (c >= ‘0‘ && c <= ‘9‘) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
return f ? x : -x;
}
int n, m;
int g[N][N];
vector<int> d(N, -inf);
int dijkstra()
{
vector<bool> vis(N, false);
for (int i = 1; i <= n; i++)
d[i] = g[i][1];
d[1] = 0;
vis[1] = 1;
for (int i = 1; i < n; i++)
{
int maxi = -1, maxn = 0;
for (int j = 1; j <= n; j++)//目前1到各点最少的承重是minn,这个节点是mini
{
if (!vis[j] && d[j]>maxn)
{
maxi = j;
maxn = d[j];
}
}
if (maxi == -1)
break;
vis[maxi] = 1;
for (int j = 1; j <= n; j++)//更新d[j](1到mini的这条线路)
{
if (!vis[j])
{
d[j] = max(d[j],min(maxn, g[j][maxi]));
}
}
}
return d[n];
}
int main()
{
int T;
cin >> T;
for (int t = 1; t <= T; t++)
{
printf("Scenario #%d:\n", t);
cin >> n >> m;
memset(g,0,sizeof(g));
for (int i = 1; i <= m; i++)
{
int u, v, w;
cin >> u >> v >> w;
g[u][v] = w;
g[v][u] = w;
}
cout << dijkstra() << endl;
cout << endl;
}
return 0;
}
C - Heavy Transportation POJ - 1797
标签:cap esc triple bitset set pat expand ted eth
原文地址:https://www.cnblogs.com/dealer/p/12683691.html