首页 > 其他分享 >Luogu P4171 [JSOI2010]满汉全席

Luogu P4171 [JSOI2010]满汉全席

时间:2022-10-25 15:37:31浏览次数:86  
标签:JSOI2010 fr int Luogu ca dfn P4171 low include


题目链接:​​传送门​

2-sat板子题
注意输入的时候可不要以为w和h后面数字只有一位


*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <complex>
#include <algorithm>
#include <climits>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define
#define

using namespace std;
typedef long long ll;
struct node {
int next, to;
}e[A];
int head[A], num;
void add(int fr, int to) {
e[++num].next = head[fr];
e[num].to = to;
head[fr] = num;
}
int dfn[A], low[A], sta[A], cnt, top, kn, vis[A], bl[A];
int n, m, a, b, x, y, T;
void tarjan(int fr) {
dfn[fr] = low[fr] = ++cnt, sta[++top] = fr, vis[fr] = 1;
for (int i = head[fr]; i; i = e[i].next) {
int ca = e[i].to;
if (!dfn[ca]) tarjan(ca), low[fr] = min(low[fr], low[ca]);
else if (vis[ca]) low[fr] = min(low[fr], dfn[ca]);
}
if (low[fr] == dfn[fr]) {
int p; kn++;
do {
p = sta[top--];
vis[p] = 0;
bl[p] = kn;
}while (p != fr);
}
}

int main(int argc, char const *argv[]) {
cin >> T;
while (T--) {
memset(vis, 0, sizeof vis);
memset(dfn, 0, sizeof dfn);
memset(low, 0, sizeof low);
memset(head, 0, sizeof head);
kn = cnt = top = num = 0;
cin >> n >> m;
for (int i = 1; i <= m; i++) {
char s1 = getchar();
while (s1 != 'm' and s1 != 'h') s1 = getchar();
x = s1 == 'm' ? 1 : 0; cin >> a;
char s2 = getchar();
while (s2 != 'm' and s2 != 'h') s2 = getchar();
y = s2 == 'm' ? 1 : 0; cin >> b;
add(a + n * x, b + n * (y ^ 1));
add(b + n * y, a + n * (x ^ 1));
}
for (int i = 1; i <= 2 * n; i++) if (!dfn[i]) tarjan(i);
for (int i = 1; i <= n; i++) if (bl[i] == bl[i + n]) {puts("BAD"); goto portal;}
puts("GOOD"); portal:;
}
}


标签:JSOI2010,fr,int,Luogu,ca,dfn,P4171,low,include
From: https://blog.51cto.com/lyle/5794772

相关文章

  • Luogu P4915 帕秋莉的魔导书
    题目链接:​​传送门​​动态开点是真的麻烦跟普通线段树差别还是挺大的题意就是区间前缀和的和除以区间长度#include<iostream>#include<cstdio>#include<cstring>#inc......
  • Luogu P4868 Preprefix sum
    题目链接:​​传送门​​线段树维护前缀和简单明了修改就修改当然还有更快的树状数组差分的做法*/#include<iostream>#include<cstdio>#include<cstring>#include<cs......
  • Luogu P4514 上帝造题的七分钟
    题目链接:​​传送门​​二维树状数组区间加区间求和烦人的输入#include<iostream>#include<cstdio>#include<cstring>#include<cstdlib>#include<complex>#include<......
  • Luogu P2455 [SDOI2006]线性方程组
    题目链接:​​传送门​​高斯消元可以去下面看一下​​​https://www.bilibili.com/video/av4688674​​​听视频比瞅博客有用得多这题算比较标准的板子了各种情况都有......
  • Luogu P3833 [SHOI2012]魔法树
    题目链接:​​传送门​​树剖板子区间加,子树查询树剖里查询的时候x和y地方小于号写反T了一会a,b写成dfn[a],dfn[b]竟然还有50分又WA了一会也就交了二十遍。#include<io......
  • Luogu P1438 无聊的数列
    题目链接:​​传送门​​还是区间加等差数列时隔8个月再写一遍这个题不会的来​这里#include<iostream>#include<cstdio>#include<cstring>#include<cstdlib>#include......
  • Luogu P3980 [NOI2008]志愿者招募
    题目链接:​​传送门​​别人家的建图~~~~好神奇很容易想到志愿者的起始时间和终止时间连边,费用就是他的费用但是每个点还有一个人数限制必须要有那么多个人也就是那么......
  • Luogu P2221 [HAOI2012]高速公路
    题目链接:​​传送门​​维护路径期望值,带区间修改看每条路径会被统计多少次贡献非常不显然是方案数就是上面的是分子下面的是分母现在要把上面的展开看怎么维护直接......
  • Luogu P2342 叠积木
    题目链接:​​传送门​​虽然看着很简单还是计较了好久!fa[]是这堆的最底下那块的编号siz[]是底块所在堆的sizeans[]就是ans,这块底下有多少块在find的时候沿路更新答案即......
  • Luogu P2150 [NOI2015]寿司晚宴
    题目链接:​​传送门​​太难了太难了题意就是问有多少种分案把一个到的排列分配为两组并使组间元素两两互质首先我们只需要考虑根号内的质因子对答案的影响,因为根号外的因......