{"trustable":false,"prependHtml":"\u003cscript\u003e window.katexOptions \u003d { disable: true }; \u003c/script\u003e\n\u003cscript type\u003d\"text/x-mathjax-config\"\u003e\n MathJax.Hub.Config({\n tex2jax: {\n inlineMath: [[\u0027$$$\u0027,\u0027$$$\u0027], [\u0027$\u0027,\u0027$\u0027]],\n displayMath: [[\u0027$$$$$$\u0027,\u0027$$$$$$\u0027], [\u0027$$\u0027,\u0027$$\u0027]]\n }\n });\n\u003c/script\u003e\n\u003cscript async src\u003d\"https://mathjax.codeforces.org/MathJax.js?config\u003dTeX-AMS-MML_HTMLorMML\" type\u003d\"text/javascript\"\u003e\u003c/script\u003e","sections":[{"title":"","value":{"format":"HTML","content":"\u003cscript type\u003d\u0027text/x-mathjax-config\u0027\u003eMathJax.Hub.Config({tex2jax: { inlineMath: [[\u0027$\u0027,\u0027$\u0027]] } }); \u003c/script\u003e\n\u003cscript type\u003d\u0027text/javascript\u0027 src\u003d\u0027https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config\u003dTeX-AMS-MML_HTMLorMML\u0027\u003e\u003c/script\u003e\n\u003cscript type\u003d\u0027text/javascript\u0027\u003esetTimeout(function(){MathJax.Hub.Queue([\u0027Typeset\u0027, MathJax.Hub, \u0027left_view\u0027]);}, 2000);\u003c/script\u003e\n\u003cdiv class\u003d\"panel_content\"\u003e\n Recognizing junk mails is a tough task. The method used here consists of two steps: \n \u003cbr\u003e1) Extract the common characteristics from the incoming email. \n \u003cbr\u003e2) Use a filter matching the set of common characteristics extracted to determine whether the email is a spam. \n \u003cbr\u003e \n \u003cbr\u003eWe want to extract the set of common characteristics from the N sample junk emails available at the moment, and thus having a handy data-analyzing tool would be helpful. The tool should support the following kinds of operations: \n \u003cbr\u003e \n \u003cbr\u003ea) “M X Y”, meaning that we think that the characteristics of spam X and Y are the same. Note that the relationship defined here is transitive, so \n \u003cbr\u003erelationships (other than the one between X and Y) need to be created if they are not present at the moment. \n \u003cbr\u003e \n \u003cbr\u003eb) “S X”, meaning that we think spam X had been misidentified. Your tool should remove all relationships that spam X has when this command is received; after that, spam X will become an isolated node in the relationship graph. \n \u003cbr\u003e \n \u003cbr\u003eInitially no relationships exist between any pair of the junk emails, so the number of distinct characteristics at that time is N. \n \u003cbr\u003ePlease help us keep track of any necessary information to solve our problem. \n\u003c/div\u003e\n\u003cbr\u003e给定n个点,m个操作。\n\u003cbr\u003eM a b 表示 a与b属于同一集合\n\u003cbr\u003eS a 表示 将a从集合删去\n\u003cbr\u003e所有操作完成后输出集合的个数\n"}},{"title":"Input","value":{"format":"HTML","content":"There are multiple test cases in the input file. \n\u003cbr\u003eEach test case starts with two integers, N and M (1 ≤ N ≤ 10 \n\u003csup\u003e5\u003c/sup\u003e , 1 ≤ M ≤ 10 \n\u003csup\u003e6\u003c/sup\u003e), the number of email samples and the number of operations. M lines follow, each line is one of the two formats described above. \n\u003cbr\u003eTwo successive test cases are separated by a blank line. A case with N \u003d 0 and M \u003d 0 indicates the end of the input file, and should not be processed by your program.\n\u003cbr\u003e输入包含多组,每组两个整数n,m(1\u003c\u003dn\u003c\u003d100000,1\u003c\u003dn\u003c\u003d1000000)\n\u003cbr\u003e接下来m行M a b或S a表示操作\n"}},{"title":"Output","value":{"format":"HTML","content":"For 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.\n\u003cbr\u003e对于每组数据,等操作结束后,输出集合的个数。"}},{"title":"Sample Input","value":{"format":"HTML","content":"\u003cpre\u003e5 6\nM 0 1\nM 1 2\nM 1 3\nS 1\nM 1 2\nS 3\n\n3 1\nM 1 2\n\n0 0\u003c/pre\u003e"}},{"title":"Sample Output","value":{"format":"HTML","content":"\u003cpre\u003eCase #1: 3\nCase #2: 2\u003c/pre\u003e"}}]}