AtCoder Grand Contest 027 C ABland Yard
思路:
用了类似拓扑排序的方法来判环
代码:
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
//#define mp make_pair
#define pb push_back
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pii pair<int, int>
#define piii pair<pii, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stout);
//head const int N = 2e5 + ;
vector<int> g[N];
char s[N];
bool vis[N];
int d[N][];
int que[N], top = ;
int main() {
int n, m, u, v;
scanf("%d %d", &n, &m);
scanf("%s", s);
for (int i = ; i <= m; i++) {
scanf("%d %d", &u, &v);
g[u].pb(v);
g[v].pb(u);
}
for (int i = ; i <= n; i++) {
for (int v : g[i]) {
d[v][s[i-] - 'A']++;
}
}
for (int i = ; i <= n; i++) {
if(!d[i][] || !d[i][]) que[++top] = i, vis[i] = true;
}
int now = ;
while(now <= top) {
int u = que[now];
for (int v : g[u]) {
d[v][s[u-] - 'A'] --;
if(!vis[v] && !d[v][s[u-] - 'A']) que[++top] = v, vis[v] = true;
}
now++;
}
if(top < n) puts("Yes");
else puts("No");
return ;
}
AtCoder Grand Contest 027 C ABland Yard的更多相关文章
- AtCoder Grand Contest 027 (AGC017) D - Modulo Matrix 构造
原文链接https://www.cnblogs.com/zhouzhendong/p/AGC027C.html 题解 首先我们假装 max mod min = 1 然后对着这个构造. 将各自黑白染色, ...
- AtCoder Grand Contest 012
AtCoder Grand Contest 012 A - AtCoder Group Contest 翻译 有\(3n\)个人,每一个人有一个强大值(看我的假翻译),每三个人可以分成一组,一组的强大 ...
- AtCoder Grand Contest 011
AtCoder Grand Contest 011 upd:这篇咕了好久,前面几题是三周以前写的... AtCoder Grand Contest 011 A - Airport Bus 翻译 有\( ...
- AtCoder Grand Contest 031 简要题解
AtCoder Grand Contest 031 Atcoder A - Colorful Subsequence description 求\(s\)中本质不同子序列的个数模\(10^9+7\). ...
- AtCoder Grand Contest 010
AtCoder Grand Contest 010 A - Addition 翻译 黑板上写了\(n\)个正整数,每次会擦去两个奇偶性相同的数,然后把他们的和写会到黑板上,问最终能否只剩下一个数. 题 ...
- AtCoder Grand Contest 009
AtCoder Grand Contest 009 A - Multiple Array 翻译 见洛谷 题解 从后往前考虑. #include<iostream> #include< ...
- AtCoder Grand Contest 008
AtCoder Grand Contest 008 A - Simple Calculator 翻译 有一个计算器,上面有一个显示按钮和两个其他的按钮.初始时,计算器上显示的数字是\(x\),现在想把 ...
- AtCoder Grand Contest 007
AtCoder Grand Contest 007 A - Shik and Stone 翻译 见洛谷 题解 傻逼玩意 #include<cstdio> int n,m,tot;char ...
- AtCoder Grand Contest 006
AtCoder Grand Contest 006 吐槽 这套题要改个名字,叫神仙结论题大赛 A - Prefix and Suffix 翻译 给定两个串,求满足前缀是\(S\),后缀是\(T\),并 ...
随机推荐
- 如何用git将项目代码上传到github
注册账户以及创建仓库 要想使用github第一步当然是注册github账号了.之后就可以创建仓库了(免费用户只能建公共仓库),Create a New Repository,填好名称后Create,之 ...
- win7使用问题解决
1. VM和主机互相PING不通 问题:桥接模式,VM可以ping 通外网,可以ping 通局域网其它机子,就是ping 不通本地主机 解决:将 vm网卡和本地网连接网卡都共享出来
- Codeforces 700B Connecting Universities - 贪心
Treeland is a country in which there are n towns connected by n - 1 two-way road such that it's poss ...
- ajax,分页器
一.ajax请求数据 ''' $.ajax({ url: '/ajax/', # 请求路径 type: 'post', # 请求方式 data: { # get和post都以data字典方式携带数据 ...
- 开源代码中的autogen.sh干了些什么?
答:重新根据当前所处环境生成新的configure 分析脚本都做了些什么? 1. 指定make工具 MAKE=gmake or MAKE=make 2. 执行autoreconf autoreconf ...
- Git 收集别名
.gitconfig文件夹一般是在C:\Users\Administrator路径下,用于全局的git的配置 下面是git别名的设置: [alias] last = log -1 --stat a = ...
- 怎样建立你自己的MASM导入库
by Iczelion (翻译:花心萝卜yqzq@163.net) 9.5.2000 这篇短文是讲述关于建立MASM导入库(import libraries)技巧,我假设你已经知道什么是导入库.在下面 ...
- IE8下面parseInt('08')、parseInt('09')会转成0
例子: <html> <body> <script type="text/javascript"> for(var i=1;i<=20;i ...
- 题解——洛谷P2734 游戏A Game 题解(区间DP)
题面 题目背景 有如下一个双人游戏:N(2 <= N <= 100)个正整数的序列放在一个游戏平台上,游戏由玩家1开始,两人轮流从序列的任意一端取一个数,取数后该数字被去掉并累加到本玩家的 ...
- (zhuan) Where can I start with Deep Learning?
Where can I start with Deep Learning? By Rotek Song, Deep Reinforcement Learning/Robotics/Computer V ...