Q-simple PathTime
limit:2000MS
Memory Limit:65536KB
64bit IO Format:%lld &%llu< /c7> SubmitStatusPracticeZOJ 3583Appoint Description:System Crawler (2015-04-16)
Description
A path with no repeated vertices of an undirected graph was called a simple path. Given an undirected graph and both verteices S and D, return the number of vertics which don ' t lie on all simple paths BETW Een S and D.
Input
The input contains multiple test cases.
Each case starts with a line of four integers, N (1 < N ≤100), M (1≤ M ≤ N ( N -1)/2), S (0 ≤ S < N ), D (0≤ <). Is the number of vertices, is the number of D N N M edges, and is, D different vertices. Then M lines follow, each line contains the different integers A (0≤ A < N ) and B (0≤ B & Lt N), which represents an edge of the graph. It's ensure that there are at least one simple path between S and D.
Output
Output the number of such vertics, one line per case.
Sample Input
4 3 0 20 11 21 34 4 0 20 11 21 32 3
Sample Output
10
The point of the simple road must be with S,d Unicom
#include <iostream> #include <cstdio> #include <cstring> #include <string> #include <cmath > #include <cstdlib> #include <algorithm> #include <queue> #include <vector> #include < Stack> #include <set>using namespace std;int n,m,s,d,mp[105][105],vis[105],mark[105];void dfs (int x) {for (int i=0;i<n;i++) {if (!vis[i]&&mp[x][i]) {vis[i]=1; DFS (i); }}}int Main () {int x, y; while (scanf ("%d%d%d%d", &n,&m,&s,&d)!=eof) {int ans=0; Memset (Mp,0,sizeof (MP)); memset (Mark,0,sizeof (Mark)); for (int i=1;i<=m;i++) {scanf ("%d%d", &x,&y); Mp[x][y]=mp[y][x]=1; } for (int i=0;i<n;i++) {memset (vis,0,sizeof (VIS)); Vis[i]=1; if (!vis[s]) DFS (s); if (!vis[d]) DFS (d); for (int j=0;j<n;j++) if (!vis[j]&&j!=s&&j!=d) Mark[j]=1; } for (int i=0;i<n;i++) if (mark[i]) ans++; printf ("%d\n", ans); } return 0;}
(Water dfs) Zoj 3583