<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      Codeforces Round #603 (Div. 2) D. Secret Passwords 并查集

      D. Secret Passwords

      One unknown hacker wants to get the admin's password of AtForces testing system, to get problems from the next contest. To achieve that, he sneaked into the administrator's office and stole a piece of paper with a list of n passwords — strings, consists of small Latin letters.

      Hacker went home and started preparing to hack AtForces. He found that the system contains only passwords from the stolen list and that the system determines the equivalence of the passwords a and b as follows:

      two passwords a and b are equivalent if there is a letter, that exists in both a and b;
      two passwords a and b are equivalent if there is a password c from the list, which is equivalent to both a and b.
      If a password is set in the system and an equivalent one is applied to access the system, then the user is accessed into the system.

      For example, if the list contain passwords "a", "b", "ab", "d", then passwords "a", "b", "ab" are equivalent to each other, but the password "d" is not equivalent to any other password from list. In other words, if:

      admin's password is "b", then you can access to system by using any of this passwords: "a", "b", "ab";
      admin's password is "d", then you can access to system by using only "d".
      Only one password from the list is the admin's password from the testing system. Help hacker to calculate the minimal number of passwords, required to guaranteed access to the system. Keep in mind that the hacker does not know which password is set in the system.

      Input

      The first line contain integer n (1≤n≤2?105) — number of passwords in the list. Next n lines contains passwords from the list – non-empty strings si, with length at most 50 letters. Some of the passwords may be equal.

      It is guaranteed that the total length of all passwords does not exceed 106 letters. All of them consist only of lowercase Latin letters.

      Output

      In a single line print the minimal number of passwords, the use of which will allow guaranteed to access the system.

      Examples

      input
      4
      a
      b
      ab
      d
      output
      2
      input
      3
      ab
      bc
      abc
      output
      1
      input
      1
      codeforces
      output
      1

      Note

      In the second example hacker need to use any of the passwords to access the system.

      題意

      現在你有n個密碼,但里面有些密碼是等價的,等價的定義是:

      假設存在一個字母x,在a和b字符串都出現過,那么a字符串和b字符串就是等價的。

      假設a字符串和c字符串等價,b和c字符串等價,那么a和b也等價。

      問你最少掌握多少個密碼,就能掌握所有密碼了

      題解

      視頻題解 https://www.bilibili.com/video/av77514280/

      并查集裸題。。。每次和自己所包含的字母合成一坨即可

      代碼

      #include<bits/stdc++.h>
      using namespace std;
      const int maxn = 3e5+7;
      int fa[maxn],n;
      string s[maxn];
      int fi(int x){
      	return fa[x]==x?fa[x]:fa[x]=fi(fa[x]);
      }
      int main(){
      	cin>>n;
      	for(int i=1;i<=n;i++){
      		cin>>s[i];
      	}
      	for(int j=1;j<=n+26;j++){
      		fa[j]=j;
      	}
      	for(int i=1;i<=n;i++){
      		for(int j=0;j<s[i].size();j++){
      			fa[fi(i)]=fa[fi(n+s[i][j]-'a'+1)];
      		}
      	}
      	int ans = 0;
      	set<int>vis;
      	for(int i=1;i<=n;i++){
      		if(!vis.count(fi(i))){
      			ans++;
      			vis.insert(fi(i));
      		}
      	}
      	cout<<ans<<endl;
      }
      
      posted @ 2019-11-30 11:33  qscqesze  閱讀(571)  評論(0)    收藏  舉報
      主站蜘蛛池模板: 亚洲中文字幕在线精品一区| 免费看婬乱a欧美大片| 日韩av中文字幕有码| 91福利一区福利二区| 亚洲人成电影网站 久久影视| 9999国产精品欧美久久久久久| 亚洲AV成人片在线观看| 无码伊人久久大杳蕉中文无码| 免费av深夜在线观看| 大香伊蕉在人线国产av| 国产欧美日韩另类在线专区| 大地资源中文第二页日本| 日韩人妻久久精品一区二区 | 99久久精品国产熟女拳交| 又爽又黄又无遮掩的免费视频| 日本高清视频网站www| 中文字幕在线日韩| 久久夜色撩人国产综合av| 亚洲av无码成人精品区一区| 一级做a爰片久久毛片下载| 非会员区试看120秒6次| 日韩熟女乱综合一区二区| 办公室强奷漂亮少妇同事| 噜噜久久噜噜久久鬼88| 国产高清在线不卡一区| 99精品国产一区二区三区不卡| 亚洲精品一区二区美女| 国产精品无码无卡在线播放| 欧美精品国产综合久久| 色综合中文字幕色综合激情| 黄又色又污又爽又高潮| 高清中文字幕国产精品| 国产精品毛片一区二区| 色吊丝一区二区中文字幕| а∨天堂一区中文字幕| 中文日产幕无线码一区中文| 日韩一区二区黄色一级片| 51午夜精品免费视频| 99久久99这里只有免费费精品| 欧美黑吊大战白妞| 成人三级视频在线观看不卡|