| Xiao Ming's Troubles--Finding the path |
| Time limit : 2000ms, Special time limit:5000ms, Memory Limit: 32768KB |
| Total Submit Users: Accepted users : 36 |
| problem 11545: No Special Judgement |
| Problem description |
Xiaoming really is a very strong person, whenever the teacher has what things, always will find Xiaoming, two Xiao Ming also can always solve, so the teacher decided to give Xiao Ming a reward, give him an extra holiday. Xiao Ming is of course very happy, because Xiao Ming finally can go out to travel. Xiao Ming's first leg of tourism to the beautiful Changsha, to Changsha, of course, to visit the antique Hunan Normal University, Xiao Ming in the normal university campus happy play, and occasionally see from his side through the beauty, also lamented the campus of the ancient buildings to his shock. Near noon, Xiao Ming went to the science gate, an instant was attracted, so went in, in the science of a classroom outside, Xiao Ming saw a boy with eyes frown, as if is what puzzles stuck, Xiao Ming's compassion heart spontaneously, then went in. So the question came: There are n cities, some cities have roads connected, but there are no gas stations in the middle of them (there are gas stations in each city), and now there is an engineer to find a different path from city 1th to N City, two paths are different when and only if not through the same edge, Now tell you the engineer's car's maximum fuel load C and the amount of oil to be consumed by each road, and ask you if the engineer can complete the task.
|
| Input |
By multiple sets of case : The first line of each group of case has 4 integers n,m,t,c,n<=200; c<=1000000; Then there's M-line. Each line has 3 integers, a,b,c, representing the amount of oil that needs C from city A to City B. c<=1000000; if there are multiple edges between two cities, it is considered a different edge.
|
| Output |
For each case: If the engineer is able to complete the task, output Yes, or output No.
|
| Sample Input |
7 9 2 51 2 22 3 53 7 51 4 14 3 14 5 75 7 11 6 36 7 37 9 2 41 2 22 3 53 7 51 4 14 3 14 5 75 7 11 6 36 7 3 |
| Sample Output |
YESNO |
| Problem Source |
| Hunnu Contest |
Test instructions: Ask if you can find the path of the T bar from 1 to n, each cannot have any overlap, the condition that each small segment path can walk is the fuel consumption is not more than C
Analysis: Network water can float over
#include <iostream> #include <cstdio> #include <cstring> #include <queue> #define MAX (b) a> B?a:b#define MIN (A, b) A<b?a:b#define Max 1000000000using namespace Std;int n,m,t,c,map[222][222];int v[222],f[222], Dis[222];int EK () { int i,j,k,l,cur,sum,mm,flag,num=0; while (true) { queue<int> q; memset (v,0,sizeof (v));//used to record each point in the process of finding n from 1 is accessed memset (f,0,sizeof (f)) ;//record 1 to N Paths Q.push (1); dis[1 ]=1<<30; flag=0; while (Q.size ())//Direct wide search for a path from 1 to n { Cur=q.front (); Q.pop (); for (i=2;i<=n;i++) if (!v[i]&&map[cur][i]<=c)// Determine if it has been visited, whether the fuel consumption is allowed through { v[i]=1; Q.push (i); f[i]=cur;//Record Path if (i==n) {flag=1;break;} If you find it, mark it and exit. Wide Search } } if (!flag| | num>=t) break;//If no path from 1 to n is found (i.e. augmented path) or the number of paths found already has a T bar, jump out of the loop Num++;//Find path number plus a for (i=n;i!=1;i=f[i])//operation found this path { map[i][f[i]]=map[f[ i]][i];//residual network, give the network flow back to the opportunity (here can not save, do not because the input is two-way omitted, when the path is the return path, it is the inverse direction of the value of Max) map[f[i]][i]=max;//is initialized to Max, indicating that it has been traversed because C is no larger than max } } if (num>=t) puts ("YES"); Else puts (" NO ");} int main (void) { int i,j,k,l; while (~scanf ("%d%d%d%d", &n,&m,&t, &C) { for (i=1;i<=n;i++) for (j=1;j<=n;j++) { map[i][j]=max;//Each section is initialized to Max, so C can not be too big to pass &nbSp } for (i=0;i<m;i++) { scanf ("%d%d%d", &j,&k,&l); map[j][k]=l;//non-Tujantu map[k][j]=l; } EK (); } return 0;}
hunnu--11545--Xiao Ming's Troubles--Find the path