题意:

  石头剪刀布 分别为1、2、3,有n轮,给出了小A这n轮出什么,然后m行,每行三个数a b k,如果k为0 表示小B必须在第a轮和第b轮的策略一样,如果k为1 表示小B在第a轮和第b轮的策略不一样,如果又一轮小B输了,那整个就输了,求小B能否战胜小A

解析:

  写出来矛盾的情况  建图就好啦

可能我建的麻烦了。。。不过。。我喜欢 hhhhh

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <map>
#include <cctype>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#define rap(i, a, n) for(int i=a; i<=n; i++)
#define rep(i, a, n) for(int i=a; i<n; i++)
#define lap(i, a, n) for(int i=n; i>=a; i--)
#define lep(i, a, n) for(int i=n; i>a; i--)
#define rd(a) scanf("%d", &a)
#define rlld(a) scanf("%lld", &a)
#define rc(a) scanf("%c", &a)
#define rs(a) scanf("%s", a)
#define pd(a) printf("%d\n", a);
#define plld(a) printf("%lld\n", a);
#define pc(a) printf("%c\n", a);
#define ps(a) printf("%s\n", a);
#define MOD 2018
#define LL long long
#define ULL unsigned long long
#define Pair pair<int, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define _ ios_base::sync_with_stdio(0),cin.tie(0)
//freopen("1.txt", "r", stdin);
using namespace std;
const int maxn = 1e5 + , INF = 0x7fffffff, LL_INF = 0x7fffffffffffffff;
int n, m;
int a[maxn];
vector<int> G[maxn];
int sccno[maxn], vis[maxn], low[maxn], scc_clock, scc_cnt;
stack<int> S;
void init()
{
mem(sccno, );
mem(vis, );
mem(low, );
scc_clock = scc_cnt = ;
for(int i = ; i < maxn; i++) G[i].clear();
} void dfs(int u)
{
low[u] = vis[u] = ++scc_clock;
S.push(u);
for(int i = ; i < G[u].size(); i++)
{
int v = G[u][i];
if(!vis[v])
{
dfs(v);
low[u] = min(low[u], low[v]);
}
else if(!sccno[v])
{
low[u] = min(low[u], vis[v]);
}
}
if(low[u] == vis[u])
{
scc_cnt++;
for(;;)
{
int x = S.top(); S.pop();
sccno[x] = scc_cnt;
if(x == u) break;
}
}
} bool check()
{
for(int i = ; i < n * ; i += )
if(sccno[i] == sccno[i + ])
{
return false;
}
return true;
} int main()
{
int T, kase = ;
cin >> T;
while(T--)
{
init();
int u, v, w;
cin >> n >> m;
for(int i = ; i < n; i++)
cin >> a[i];
for(int i = ; i <= m; i++)
{
cin >> u >> v >> w;
u--, v--;
int x = a[u], y = a[v];
if(w == )
{
if(x == y)
{
G[u << ].push_back(v << | );
G[v << | ].push_back(u << );
G[u << | ].push_back(v << );
G[v << ].push_back(u << | );
}
else if(x != y)
{
if(x == && y == || y == && x == )
{
if(y == && x == )
swap(u, v);
G[u << | ].push_back(v << | ), G[v << ].push_back(u << );
}
else if(x == && y == || y == && x == )
{
if(y == && x == )
swap(u, v);
G[v << | ].push_back(u << | ), G[u << ].push_back(v << );
}
else if(x == && y == || x == && y == )
{
if(x == && y == )
swap(u, v);
G[u << | ].push_back(v << | ), G[v << ].push_back(u << );
}
}
}
else
{
if(x == y)
{
G[u << ].push_back(v << ), G[u << | ].push_back(v << | );
G[v << ].push_back(u << ), G[v << | ].push_back(u << | );
}
else
{
if(x == && y == || x == && y == )
{
if(x == && y == ) swap(u, v);
G[u << | ].push_back(v << ), G[v << ].push_back(u << | );
G[u << ].push_back(u << | ), G[v << | ].push_back(v << );
}
else if(x == && y == || x == && y == )
{
if(x == && y == ) swap(u, v);
G[u << ].push_back(v << | ), G[v << | ].push_back(u << );
G[u << | ].push_back(u << ), G[v << ].push_back(v << | );
}
else if(x == && y == || y == && x == )
{
if(y == && x == ) swap(u, v);
G[u << | ].push_back(v << ), G[v << ].push_back(u << | );
G[u << ].push_back(u << | ), G[v << | ].push_back(v << );
}
}
}
}
for(int i = ; i < n * ; i++)
if(!vis[i]) dfs(i);
printf("Case #%d: ", ++kase);
if(check())
{
cout << "yes" << endl;
}
else cout << "no" << endl;
} return ;
}
05-11 21:57