HDU 5486 difference of clustering graph theory

Source: Internet
Author: User

Topic Links:

http://acm.hdu.edu.cn/showproblem.php?pid=5486

Test instructions

Give you each element at the beginning of the collection to which it belongs, and the last collection to which it belongs, ask how many times the collection is detached, and the operation and the invariant operation.

Separation: [M1,M2,M3]->[M1],[M2],[M3]

Merging: inverse operation of separation

Unchanged: [M1,M2,M3]->[M1,M2,M3]

Exercises

Build a set of units, (an element from the collection S1 to S2 constructs an edge join collection S1,S2, note to delete the heavy edges)

Then for each point, the point adjacent to it, if the degree is 1, is the detach operation,

Transpose the picture, then run it again the separation is the merger.

If a collection has only one link to its own side, then it is a 1:1 operation.

Code:
 #include <iostream> #include <cstdio> #include <map> #include <vector> #include <algorithm > #include <cstring>using namespace std;const int maxn = 1e6 + 10;int n,_max;map<pair<int, Int>, int> m P;vector<int> G[MAXN], G2[maxn];int IN[MAXN], in2[maxn];void init () {_max = -1;mp.clear (); for (int i = 0; I <maxn ; i++) G[i].clear (), G2[i].clear (), memset (in, 0, sizeof (in)), memset (in2, 0, sizeof (in2));} int main () {int tc,kase=0;scanf ("%d", &AMP;TC), while (tc--) {scanf ("%d", &n), Init (); for (int i = 0; i < n; i++) {in t u, V;_max = max (_max, u), _max = max (_max, v), scanf ("%d%d", &u, &v), if (!mp[make_pair (U, v)]) {Mp[make_pair (U, v) ]++; G[u].push_back (v); in[v]++; G2[v].push_back (u); in2[u]++;}}  int ans1=0, ans2=0,ans3=0;for (int i = 0; I <= _max; i++) {int su = 1;for (int j = 0; J < G[i].size (), j + +) {int v = G[i][j];if (In[v] > 1) {su = 0; break;}} if (su) {if (g[i].size () = = 1) ans3++;else if (g[i].size () >1) ans2++;}} for (int i =0; I <= _max; i++) {int su = 1;for (int j = 0; J < G2[i].size (), j + +) {int v = g2[i][j];if (In2[v] > 1) {su = 0; break;}} if (su) {if (g2[i].size () = = 1); else if (G2[i].size () >1) ans1++;}} printf ("Case #%d:%d%d%d\n", ++kase, Ans2,ans1, ANS3);} return 0;}

HDU 5486 difference of clustering graph theory

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.