五月天青色头像情侣网名,国产亚洲av片在线观看18女人,黑人巨茎大战俄罗斯美女,扒下她的小内裤打屁股

歡迎光臨散文網(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的評論 (共 條)

分享到微博請遵守國家法律
石楼县| 泊头市| 武邑县| 祁阳县| 漳平市| 吉安市| 关岭| 彰化市| 吴旗县| 吉隆县| 南平市| 塔城市| 商丘市| 栖霞市| 格尔木市| 汕尾市| 滕州市| 抚顺县| 昌江| 蕉岭县| 泰宁县| 石屏县| 保靖县| 新昌县| 乳源| 南充市| 平潭县| 黄骅市| 清丰县| 汤原县| 保山市| 浦城县| 当阳市| 彩票| 衡南县| 微山县| 同德县| 亳州市| 水富县| 南宫市| 龙海市|