亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

【BZOJ】1050: [HAOI2006]旅行comf(暴力+并查

系統 1673 0

http://www.lydsy.com/JudgeOnline/problem.php?id=1050

表示被暴力嚇到了orz

我竟然想不到。。。我竟然還想到分數規劃,,但是不可做。。。然后又想到最小生成樹,,然后不會做orz

我一直在糾結怎么最大化(或最小化)分母和最小化(或最大化)分子的做法。。。。。但是。。。。不會orz

沒想到是暴力orz

直接排序后枚舉最小的邊,生成樹后要最大的邊最小(排序后即可orz),然后更新答案即可。

但是不知道之前寫錯了啥wa了兩發,,,隨便改改才過orz

      #include <cstdio>

#include <cstring>

#include <cmath>

#include <string>

#include <iostream>

#include <algorithm>

#include <queue>

#include <set>

#include <map>

using namespace std;

typedef long long ll;

#define pii pair<int, int>

#define mkpii make_pair<int, int>

#define pdi pair<double, int>

#define mkpdi make_pair<double, int>

#define pli pair<ll, int>

#define mkpli make_pair<ll, int>

#define rep(i, n) for(int i=0; i<(n); ++i)

#define for1(i,a,n) for(int i=(a);i<=(n);++i)

#define for2(i,a,n) for(int i=(a);i<(n);++i)

#define for3(i,a,n) for(int i=(a);i>=(n);--i)

#define for4(i,a,n) for(int i=(a);i>(n);--i)

#define CC(i,a) memset(i,a,sizeof(i))

#define read(a) a=getint()

#define print(a) printf("%d", a)

#define dbg(x) cout << (#x) << " = " << (x) << endl

#define error(x) (!(x)?puts("error"):0)

#define printarr2(a, b, c) for1(_, 1, b) { for1(__, 1, c) cout << a[_][__]; cout << endl; }

#define printarr1(a, b) for1(_, 1, b) cout << a[_] << '\t'; cout << endl

inline const int getint() { int r=0, k=1; char c=getchar(); for(; c<'0'||c>'9'; c=getchar()) if(c=='-') k=-1; for(; c>='0'&&c<='9'; c=getchar()) r=r*10+c-'0'; return k*r; }

inline const int max(const int &a, const int &b) { return a>b?a:b; }

inline const int min(const int &a, const int &b) { return a<b?a:b; }



const int N=1005, M=10005;

struct dat { int x, y, w; }a[M];

inline const bool cmp(const dat &a, const dat &b) { return a.w<b.w; }

int p[N], ans1, ans2, n, m;

const int ifind(const int &x) { return x==p[x]?x:p[x]=ifind(p[x]); }

const int gcd(const int &a, const int &b) { return !b?a:gcd(b, a%b); }



int main() {

	read(n); read(m);

	for1(i, 1, m) read(a[i].x), read(a[i].y), read(a[i].w);

	int s=getint(), t=getint();

	sort(a+1, a+1+m, cmp);

	bool flag=1;

	for1(i, 1, m) {

		for1(j, 1, n) p[j]=j;

		int j=i;

		for(; j<=m; ++j) {

			int fx=ifind(a[j].x), fy=ifind(a[j].y);

			p[fx]=fy;

			if(ifind(s)==ifind(t)) {

				flag=0;

				if(a[j].w*ans2<=a[i].w*ans1) ans1=a[j].w, ans2=a[i].w;

				break;

			}

		}

		if(ifind(s)!=ifind(t)) break;

		if(a[j].w*ans2<=a[i].w*ans1) ans1=a[j].w, ans2=a[i].w;

	}

	if(flag) { puts("IMPOSSIBLE"); return 0; }

	int d=gcd(ans1, ans2);

	ans1/=d; ans2/=d;

	if(ans2==1) printf("%d\n", ans1);

	else printf("%d/%d\n", ans1, ans2);

	return 0;

}


    

?


?

?

Description

給你一個無向圖,N(N<=500)個頂點, M(M<=5000)條邊,每條邊有一個權值Vi(Vi<30000)。給你兩個頂點S和T,求一條路徑,使得路徑上最大邊和最小邊的比值最小。如果S和T之間沒有路徑,輸出”IMPOSSIBLE”,否則輸出這個比值,如果需要,表示成一個既約分數。 備注: 兩個頂點之間可能有多條路徑。

Input

第一行包含兩個正整數,N和M。 下來的M行每行包含三個正整數:x,y和v。表示景點x到景點y之間有一條雙向公路,車輛必須以速度v在該公路上行駛。 最后一行包含兩個正整數s,t,表示想知道從景點s到景點t最大最小速度比最小的路徑。s和t不可能相同。

Output

如果景點s到景點t沒有路徑,輸出“IMPOSSIBLE”。否則輸出一個數,表示最小的速度比。如果需要,輸出一個既約分數。

Sample Input

【樣例輸入1】
4 2
1 2 1
3 4 2
1 4
【樣例輸入2】
3 3
1 2 10
1 2 5
2 3 8
1 3
【樣例輸入3】
3 2
1 2 2
2 3 4
1 3

Sample Output

【樣例輸出1】
IMPOSSIBLE
【樣例輸出2】
5/4
【樣例輸出3】
2

HINT

?

【數據范圍】

1< ?N < = 500

1 < = x, y < = N,0 < v < 30000,x ≠ y

0 < M < =5000

?

Source

?

?

【BZOJ】1050: [HAOI2006]旅行comf(暴力+并查集)


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 国产亚洲精品久久 | 视频综合网 | 国内高清久久久久久久久 | 人人狠狠综合久久亚洲婷婷 | 久久久这里只有免费精品2018 | 精品久久久久久久久久香蕉 | 香蕉视频在线看 | 久久99国产乱子伦精品免 | 国产日韩不卡免费精品视频 | 欧美日韩国产一区二区 | 欧美日韩在线观看视频 | 精品国产福利久久久 | 日本午夜www高清视频 | 性一级视频 | 午夜一区二区在线观看 | 国产一区二区三区久久 | 四虎+网站+影院+网站 | 国产香蕉精品视频 | 日韩中文字幕一区二区不卡 | 91精品一区二区三区久久久久 | 国产啪爱视频精品免视 | 久久这里只精品国产99热8 | 亚洲精品国产专区一区 | 尹人久久 | 欧美日韩高清在线观看一区二区 | 日日夜夜中文字幕 | 久久久综合| 五月天亚洲婷婷 | 欧美午夜片 | 亚洲四虎永久在线播放 | 亚洲国产成人久久精品hezyo | 色老头网站久久网 | 九九色| 日日摸夜夜摸人人嗷嗷叫 | 久久这里只有免费精品6www | 91国色| 久久99精品久久久 | 亚洲欧美日韩国产精品影院 | 老头与老头同性tube可播放 | 正在播放亚洲 | 综合亚洲欧美日韩一区二区 |