UVa 11324 the largest clique/strong connectivity component

Source: Internet
Author: User

There is a direction graph G to find the node set with the largest number of nodes where any 2 points u and v either u can be to V or V can be to u or to each other to reach

First, each of the strongly connected components is accessible, and the weight of each point on a path path is the maximum number of nodes of the strongly connected component, which can be written by a memory search.

#include <cstdio> #include <cstring> #include <vector> #include <stack> using namespace std;
const int MAXN = 1010;
Vector <int> G[MAXN];
Stack <int> s;
int PRE[MAXN];
int LOW[MAXN];
int CNT[MAXN];
int DEGREE[MAXN];
int sccno[maxn];//the scc_cnt int dfs_clock of the strong unicom component of each point;
int scc_cnt;
int n, m;
Vector <int> A[MAXN];

int D[MAXN];
	void Dfs (int u) {pre[u] = low[u] = ++dfs_clock;
	S.push (U);
		for (int i = 0; i < g[u].size (); i++) {int v = g[u][i];
			if (!pre[v]) {DFS (v);
		Low[u] = min (Low[u], low[v]);
		} else if (!sccno[v]) {Low[u] = min (Low[u], pre[v]);
		}} if (low[u] = = Pre[u]) {scc_cnt++;
			while (1) {int x = S.top ();
			S.pop ();
			SCCNO[X] = scc_cnt;
			cnt[scc_cnt]++;
		if (x = = u) break;
	}}} void Find_scc () {dfs_clock = scc_cnt = 0;
	memset (sccno, 0, sizeof (SCCNO));
	memset (pre, 0, sizeof (pre));
	
for (int i = 1; I <= n; i++) if (!pre[i]) DFS (i); } int DP (int u) {if (D[u]! =-1) return D[u];
	D[u] = Cnt[u];
	int ans = 0;
		for (int i = 0; i < a[u].size (); i++) {int v = a[u][i];
		int temp = DP (v);
	ans = max (ans, temp);
	} D[u] + = ans;
return D[u];
	} int main () {int T;
	scanf ("%d", &t);
		while (t--) {scanf ("%d%d", &n, &m);
			for (int i = 1; I <= n; i++) {g[i].clear ();
		A[i].clear ();
			} for (int i = 1; I <= m; i++) {int u, v;
			scanf ("%d%d", &u, &v);
		G[u].push_back (v);
		} memset (degree, 0, sizeof (degree));
		memset (CNT, 0, sizeof (CNT));
		memset (d,-1, sizeof (d));
		FIND_SCC ();
				for (int u = 1, u <= n; u++) {for (int i = 0; i < g[u].size (); i++) {int v = g[u][i];
					if (sccno[u]! = Sccno[v]) {a[sccno[u]].push_back (sccno[v]);
				degree[sccno[v]]++;
		}}} int ans = 0;
				for (int i = 1; I <= scc_cnt; i++) {if (!degree[i]) {int temp = DP (i);
			ans = max (ans, temp);
	}} printf ("%d\n", ans);
} return 0; }


 

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.