uva10048|uva10048 Audiophobia

Root :: Problem Set Volumes (100...1999) :: Volume 9 (900-999) uva10048|uva10048 Audiophobia
文章图片
uva10048|uva10048 Audiophobia
文章图片
uva10048|uva10048 Audiophobia
文章图片
10048 - Audiophobia
Time limit: 3.000 seconds
Problem B: Audiophobia
Consider yourself lucky! Consider yourself lucky to be still breathing and having fun participating in this contest. But we apprehend that many of your descendants may not have this luxury. For, as you know, we are the dwellers of one of the most polluted cities on earth. Pollution is everywhere, both in the environment and in society and our lack of consciousness is simply aggravating the situation.
However, for the time being, we will consider only one type of pollution -- the sound pollution. The loudness or intensity level of sound is usually measured in decibels and sound having intensity level 130 decibels or higher is considered painful. The intensity level of normal conversation is 60-65 decibels and that of heavy traffic is 70-80 decibels.
Consider the following city map where the edges refer to streets and the nodes refer to crossings. The integer on each edge is the average intensity level of sound (in decibels) in the corresponding street.

To get from crossing A to crossing G you may follow the following path: A-C-F-G. In that case you must be capable of tolerating sound intensity as high as 140 decibels. For the paths A-B-E-G, A-B-D-G and A-C-F-D-G you must tolerate respectively 90, 120 and 80 decibels of sound intensity. There are other paths, too. However, it is clear that A-C-F-D-G is the most comfortable path since it does not demand you to tolerate more than 80 decibels.
In this problem, given a city map you are required to determine the minimum sound intensity level you must be able to tolerate in order to get from a given crossing to another.

InputThe input may contain multiple test cases.
The first line of each test case contains three integers ,andwhere Cindicates the number of crossings (crossings are numbered using distinct integers ranging from 1 to C), Srepresents the number of streets and Q is the number of queries.
Each of the next S lines contains three integers: c1, c2 and d indicating that the average sound intensity level on the street connecting the crossings c1 and c2 ( ) is d decibels.
Each of the next Q lines contains two integers c1 and c2 ( ) asking for the minimum sound intensity level you must be able to tolerate in order to get from crossing c1 to crossing c2.
The input will terminate with three zeros form C, S and Q.

OutputFor each test case in the input first output the test case number (starting from 1) as shown in the sample output. Then for each query in the input print a line giving the minimum sound intensity level (in decibels) you must be able to tolerate in order to get from the first to the second crossing in the query. If there exists no path between them just print the line ``no path".
Print a blank line between two consecutive test cases.

Sample Input
7 9 3 1 2 50 1 3 60 2 4 120 2 5 90 3 6 50 4 6 80 4 7 70 5 7 40 6 7 140 1 7 2 6 6 2 7 6 3 1 2 50 1 3 60 2 4 120 3 6 50 4 6 80 5 7 40 7 5 1 7 2 4 0 0 0

Sample Output
Case #1 80 60 60 Case #2 40 no path 80


本来就是道水题,但是貌似被学弟问道把点数改成10^4,边数改成10^5,询问改成10^5,求任意两点间的路径上的最大值最小怎么做,觉得有必要去拍一下,结果就真是觉得不做死就不会死,最后把两种解法写到了一起,于是代码量就突破天际了,呜呜,哭了。。。。。。
因为可能最后的生成的是森林,那么就用正常的Floyd做,当是一棵生成树的时候,树链剖分就来了,唉,表示我只是来测试的,代码已经不忍目视了。
当然还有一种做法就是模拟kruskal的过程,一条边一条边的加入树中,每加入一次,就判断起点和终点是否在一个集合里, 一旦他们在一个集合里了,那么那条路径中的最大值便是当前加入的这条边的权值,因为加入的边是按照从小到大顺序加入的。
uva10048|uva10048 Audiophobia
文章图片
uva10048|uva10048 Audiophobia
文章图片
1 #include 2 #include 3 #include 4 #include 5 #define maxn 100010 6 #define inf 0x3f3f3f3f 7 using namespace std; 8 int n,m,q; 9 struct spanning_tree{ 10int u,v,l; 11friend bool operator<(spanning_tree a,spanning_tree b){ 12return a.l=size[son[u]]) son[u]=v; 68size[u]+=size[v]; 69} 70} 71 } 72 void build_tree(int x,int f){ 73w[x]=tn++,fa[x]=f; 74for(int i=head[x]; i!=-1; i=e[i].next){ 75if(e[i].v==son[x]){ 76len[tn]=e[i].l,build_tree(son[x],fa[x]); 77break; 78} 79} 80for(int i=head[x]; i!=-1; i=e[i].next){ 81int v=e[i].v; 82if(v!=pre[x]&&v!=son[x]){ 83len[tn]=e[i].l; 84build_tree(v,v); 85} 86} 87 } 88 struct tree{ 89int l,r,maxv; 90 }a[maxn*4]; 91 void build(int l,int r,int k){ 92a[k].l=l,a[k].r=r; 93if(l==r){ 94a[k].maxv=len[l]; 95}else{ 96int mid=(l+r)>>1; 97build(l,mid,k<<1); 98build(mid+1,r,k<<1|1); 99a[k].maxv=max(a[k<<1].maxv,a[k<<1|1].maxv); 100} 101 } 102 int query(int l,int r,int k){ 103if(l<=a[k].l&&a[k].r<=r){ 104return a[k].maxv; 105}else{ 106int mid=(a[k].l+a[k].r)>>1; 107if(r<=mid) return query(l,r,k<<1); 108else if(l>mid) return query(l,r,k<<1|1); 109else return max(query(l,mid,k<<1),query(mid+1,r,k<<1|1)); 110} 111 } 112 int cal(int x,int y){ 113int ret=0; 114while(fa[x]!=fa[y]&&x!=y){ 115if(dep[fa[x]]>dep[fa[y]]) swap(x,y); 116//cout<1) printf("\n"); 151printf("Case #%d\n",cas); 152for(int i=0; i1) printf("\n"); 167printf("Case #%d\n",cas); 168for(int i=0; in||v>n) printf("no path\n"); 171else printf("%d\n",cal(u,v)); 172} 173 } 174 int main(){ 175//freopen("10048.txt","w",stdout); 176int cas=1; 177while(~scanf("%d%d%d",&n,&m,&q)){ 178if(n==0&&m==0&&q==0) break; 179read(); 180solve(cas++); 181} 182return 0; 183 }

uva10048
uva10048|uva10048 Audiophobia
文章图片
【uva10048|uva10048 Audiophobia】转载于:https://www.cnblogs.com/wonderzy/p/3439486.html

    推荐阅读