Junk-mail Filter
Time limit:15000/8000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 7515 Accepted Submission (s): 2368
Problem descriptionrecognizing junk mails is a tough task. The method used here consists of the steps:
1) Extract The common characteristics from the incoming email.
2) Use a filter matching the set of common characteristics extracted to determine whether the e-mail is a spam.
We want to extract the set of common characteristics from the N sample junk emails available at the moment, and thus havin G A handy data-analyzing tool would be helpful. The tool should support the following kinds of operations:
A) "M X Y", meaning that we think so the characteristics of spam X and Y are the same. Note that the relationship defined are transitive, so
Relationships (other than, the one between X and Y) need to be created if they is not present at the moment.
b) "S X", meaning that we think spam X had been misidentified. Your tool should remove all relationships that spam X have when the This command is received; After that, spam X would become an isolated node in the relationship graph.
Initially no relationships exist between any pair of the junk emails, so the number of distinct characteristics at that Ti Me is N.
Keep track of any necessary information to solve US problem.
Inputthere is multiple test cases in the input file.
Each test case starts with integers, N and M (1≤n≤105, 1≤m≤106), the number of email samples and the number O F Operations. M lines follow, each of which is one of the formats described above.
Successive test cases is separated by a blank line. A case with N = 0 and M = 0 indicates the end of the input file, and should not being processed by your program.
Outputfor Each test case, please print a single integer, the number of distinct common characteristics, to the console. Follow the format as indicated in the sample below.
Sample Input5 6M 0 1M 1 2M 1 3S 1M 1 2S 3 3 1M 1 2 0 0
Sample outputcase #1:3Case #2:2 and check the deletion of the detailed details see: Point I open the link
#include <stdio.h> #include <string.h> #define MAX 1001000int set[max],vis[max];int mark[max];int n,m,count void init () {int i,j;for (i=0;i<n;i++) {set[i]=i;vis[i]=i;}} int find (int fa) {int t;int ch=fa;while (Fa!=set[fa]) fa=set[fa];while (CH!=FA) {t=set[ch];set[ch]=fa;ch=t;} return FA;} void Mix (int x,int y) {int fx,fy;fx=find (x); Fy=find (y); if (Fx!=fy) set[fx]=fy;} void Getmap () {int I,j,k=n;char a[2]; Memset (A, ' mm ', sizeof (a)), for (i=0;i<m;i++) {scanf ("%s", a), if (a[0]== ' m ') {int b,c;scanf ("%d%d", &b,&c); Mix (Vis[b],vis[c]);} Else{int b;scanf ("%d", &b); vis[b]=k;set[k]=k;k++;}}} void Solve () {int i,ans=0;memset (mark,0,sizeof (Mark)), for (i=0;i<n;i++) {int stem=find (vis[i]), if (!mark[stem]) { Ans++;mark[stem]=1;}} printf ("Case #%d:%d\n", Count++,ans);} int main () {count=1; while (scanf ("%d%d", &n,&m), n|m) { init (); Getmap (); Solve (); } return 0;}
Hdoj 2473 junk-mail Filter "and check node deletion"