(Water dfs) Zoj 3583

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.