最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

USACO2023JanuarySilverProblem1FindandReplace

2023-07-26 10:39 作者:信奧賽USACO鄭老師  | 我要投稿

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

int main() {

? ? int T;

? ? cin>>T;

? ? while(T>0){

? ? ? ? vector<int> g(128),inDegree(128);

? ? ? ? T--;

? ? ? ? string s,t;

? ? ? ? cin>>s>>t;

? ? ? ? bool miss=false;

? ? ? ? set<int> allc,outchar;

? ? ? ? set<pair<int,int>> inpair;

? ? ? ? bool notAlleq=false;

? ? ? ? for(int i=0;i<s.size();i++){

? ? ? ? ? ? int a=(int)s[i], b=(int)t[i];

? ? ? ? ? ? if(inpair.count(make_pair(a,b))>0){//ignore duplicated pairs

? ? ? ? ? ? ? ? continue;

? ? ? ? ? ? }else{

? ? ? ? ? ? ? ? inpair.insert(make_pair(a,b));

? ? ? ? ? ? }

? ? ? ? ? ? if(g[a]>0&&g[a]!=b){

? ? ? ? ? ? ? ? miss=true;

? ? ? ? ? ? ? ? break;

? ? ? ? ? ? }

? ? ? ? ? ? outchar.insert(b);

? ? ? ? ? ? allc.insert(a), allc.insert(b);

? ? ? ? ? ? if(a!=b){

? ? ? ? ? ? ? ? notAlleq=true;

? ? ? ? ? ? }

? ? ? ? ? ? g[a]=b;

? ? ? ? ? ? inDegree[b]++;

? ? ? ? }

? ? ? ? if(miss){

? ? ? ? ? ? cout<<-1<<endl;

? ? ? ? ? ? continue;

? ? ? ? }

? ? ? ? if(outchar.size()==52&&!(s==t)){

? ? ? ? ? ? cout<<-1<<endl;

? ? ? ? ? ? continue;

? ? ? ? }? ? ? ??

? ? ? ? int ans=0;

? ? ? ? int count=0;

? ? ? ? for(int c:allc){

? ? ? ? ? ? if(g[c]>0){

? ? ? ? ? ? ? ? if(g[c]!=c){

? ? ? ? ? ? ? ? ? ? ans++;? ? ? ? ? ? ? ? ? ? ? ??

? ? ? ? ? ? ? ? }else{

? ? ? ? ? ? ? ? ? ? g[c]=0;

? ? ? ? ? ? ? ? }

? ? ? ? ? ? }

? ? ? ? }

? ? ? ? //find all pure cycle to add ans

? ? ? ? vector<int> pathRec(128);

? ? ? ? for(int c:allc){

? ? ? ? ? ? if(pathRec[c]>0){

? ? ? ? ? ? ? ? continue;

? ? ? ? ? ? }

? ? ? ? ? ? int a=c;

? ? ? ? ? ? bool endFound=false;

? ? ? ? ? ? bool hasInDegreeMoreThanOne=false;

? ? ? ? ? ? while(pathRec[a]==0){

? ? ? ? ? ? ? ? pathRec[a]=c;

? ? ? ? ? ? ? ? if(inDegree[a]>1){

? ? ? ? ? ? ? ? ? ? hasInDegreeMoreThanOne=true;

? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? if(g[a]>0){

? ? ? ? ? ? ? ? ? ? a=g[a];

? ? ? ? ? ? ? ? }else{

? ? ? ? ? ? ? ? ? ? endFound=true;

? ? ? ? ? ? ? ? ? ? break;

? ? ? ? ? ? ? ? }? ? ? ? ? ? ? ??

? ? ? ? ? ? }

? ? ? ? ? ? if(!endFound&&pathRec[a]==c&&!hasInDegreeMoreThanOne){

? ? ? ? ? ? ? ? ans++;

? ? ? ? ? ? }

? ? ? ? }

? ? ? ? cout<<ans<<endl;

? ? }

? ? return 0;

}


USACO2023JanuarySilverProblem1FindandReplace的評論 (共 條)

分享到微博請遵守國家法律
平顺县| 张家川| 崇明县| 浏阳市| 安平县| 曲靖市| 长阳| 新津县| 讷河市| 鄢陵县| 蒲城县| 新绛县| 屏山县| 平安县| 苏尼特左旗| 墨玉县| 离岛区| 炎陵县| 揭东县| 隆安县| 安吉县| 龙岩市| 鲁山县| 莱芜市| 泗洪县| 龙江县| 遂宁市| 梧州市| 神木县| 积石山| 通道| 武威市| 勐海县| 昭平县| 南阳市| 大余县| 太和县| 阿瓦提县| 漳州市| 视频| 南通市|