P2502 [HAOI2006]鏃呰 鏈€灏忕敓鎴愭爲
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了P2502 [HAOI2006]鏃呰 鏈€灏忕敓鎴愭爲相关的知识,希望对你有一定的参考价值。
鏍囩锛?a href='http://www.mamicode.com/so/1/code' title='code'>code opera sdi unsigned break mes dig else 鏃呰
鎬濊矾锛氭灇涓捐竟闆嗭紝鏈€灏忕敓鎴愭爲
鎻愪氦锛?娆?/p>
棰樿В锛氾紙濡傛€濊矾锛?/p>
#include<cstdio> #include<iostream> #include<algorithm> #define R register int using namespace std; #define ull unsigned long long #define ll long long #define pause (for(R i=1;i<=10000000000;++i)) #define In freopen("NOIPAK++.in","r",stdin) #define Out freopen("out.out","w",stdout) namespace Fread static char B[1<<15],*S=B,*D=B; #ifndef JACK #define getchar() (S==D&&(D=(S=B)+fread(B,1,1<<15,stdin),S==D)?EOF:*S++) #endif inline int g() R ret=0,fix=1; register char ch; while(!isdigit(ch=getchar())) fix=ch==鈥?/span>-鈥?/span>?-1:fix; if(ch==EOF) return EOF; do ret=ret*10+(ch^48); while(isdigit(ch=getchar())); return ret*fix; inline bool isempty(const char& ch) return (ch<=36||ch>=127); inline void gs(char* s) register char ch; while(isempty(ch=getchar())); do *s++=ch; while(!isempty(ch=getchar())); using Fread::g; using Fread::gs; namespace Luitaryi const int N=510,M=5010; int n,m,s,t,up,dn; double anss=1E+9; int fa[N]; struct edge int u,v,w; inline bool operator < (const edge& that) constreturn w<that.w; e[M]; inline int getf(int x) return x==fa[x]?x:fa[x]=getf(fa[x]); inline void main() n=g(),m=g(); for(R i=1;i<=m;++i) e[i].u=g(),e[i].v=g(),e[i].w=g(); sort(e+1,e+m+1); s=g(),t=g(); for(R i=1;i<=m;++i) R ans=0;//鏋氫妇涓嬬晫锛屾渶灏忕殑杈? for(R j=1;j<=n;++j) fa[j]=j; for(R j=i;j<=m;++j) //寰€涓婃灇涓撅紝鐩村埌涓ょ偣杩為€? R uf=getf(e[j].u),vf=getf(e[j].v); fa[uf]=vf; if(getf(s)==getf(t)) ans=j; break; if(i==1&&ans==0) return (void)printf("IMPOSSIBLE\n"); if(ans==0) break; register double tmp=1.0*e[ans].w/e[i].w; if(tmp<anss) anss=tmp,up=e[ans].w,dn=e[i].w; R tmp=__gcd(up,dn); if(tmp==dn) printf("%d\n",up/dn); else printf("%d/%d\n",up/tmp,dn/tmp); signed main() Luitaryi::main(); return 0;
2019.07.20
以上是关于P2502 [HAOI2006]鏃呰 鏈€灏忕敓鎴愭爲的主要内容,如果未能解决你的问题,请参考以下文章
luogu题解P2502[HAOI2006]旅行--最小生成树变式