国产精品天干天干,亚洲毛片在线,日韩gay小鲜肉啪啪18禁,女同Gay自慰喷水

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

分享到微博請遵守國家法律
措勤县| 霍州市| 什邡市| 海宁市| 元阳县| 松阳县| 秦安县| 海安县| 浪卡子县| 五指山市| 峨山| 普陀区| 乃东县| 合川市| 房产| 陵川县| 岱山县| 枝江市| 宜川县| 古交市| 祁门县| 宁远县| 金沙县| 昌黎县| 泗阳县| 长岛县| 三门峡市| 兴仁县| 涪陵区| 习水县| 裕民县| 海淀区| 武乡县| 原平市| 邓州市| 沈丘县| 漯河市| 长汀县| 永修县| 启东市| 澳门|