40分求助,判断"h23"这种两位数问题还是错了!
查看原帖
40分求助,判断"h23"这种两位数问题还是错了!
121260
mikechu楼主2020/5/23 15:26

rt,

#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll t,n,m,dfn[2010],low[2010],cnt,num,tjvis[210];
ll h[2010];
vector<ll> g[2010];
stack<ll> st;
bool ist[2010];
void tarjan(ll u){
	//printf("tarjan %lld %lld start\n",u,fa);
	dfn[u] = low[u] = ++cnt;
	st.push(u);
	ist[u]=1;
	for(ll i=0;i<g[u].size();i++){
		ll v = g[u][i];
		if(!dfn[v])tarjan(v),low[u] = min(low[u],low[v]);
		else if(ist[i])low[u] = min(low[u],dfn[v]);
	}
	//printf("low[%lld] = %lld,dfn[%lld] = %lld\n",u,low[u],u,dfn[u]);
	if(low[u] == dfn[u]){
		num++;
		ll i;
		while(1){
			i = st.top();
			//h[num].push_back(i);
			h[i] = num;
			//printf("h[%lld].push_back(%lld)\n",num,i);
			ist[i] = 0;
			st.pop();
			if(i == u)break;
		}
	}
	//printf("tarjan %lld %lld over\n",u,fa);
}
int main(){
	cin >> t;
	while(t--){
		cin >> n >> m;
		for(ll i=1;i<=2009;i++)g[i].clear();
		memset(h,0,sizeof(h));
		memset(dfn,0,sizeof(dfn));
		memset(low,0,sizeof(low));
		memset(ist,0,sizeof(ist));
		cnt=0;num=0;
		while(!st.empty())st.pop();
		for(ll s1,s2,i=1;i<=m;i++){
			char c1,c2;bool f1,f2;
			c1=0;
			while(c1 != 'm' && c1 != 'h')c1 = getchar();
			//scanf("%c%lld %c%lld",c1,s1,c2,s2);
			cin >> s1;
			getchar();c2 = getchar();
			cin >> s2;
			printf("c1 = %c,s1 = %lld,c2 = %c,s2 = %lld\n",c1,s1,c2,s2);
			if(c1 == 'm')f1 = 0;
			else f1 = 1;
			if(c2 == 'm')f2 = 0;
			else f2 = 1;
			g[!f1 * n + s1].push_back(f2 * n + s2);
			g[!f2 * n + s2].push_back(f1 * n + s1);
			printf("join %lld to %lld,%lld to %lld\n",!f1*n+s1,f2*n+s2,!f2 * n + s2,f1 * n + s1);
		}
		for(ll i=1;i<=n*2;i++){
			if(!dfn[i])tarjan(i);
		}
		bool f=0;
		for(ll i=1;i<=n;i++){
			if(h[i] == h[i+n])f=1;
		}
		if(f == 1){
			cout << "BAD\n";
		}
		else cout << "GOOD\n";
	}
}
2020/5/23 15:26
加载中...