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的更多相关文章

  1. AtCoder Grand Contest 027 (AGC017) D - Modulo Matrix 构造

    原文链接https://www.cnblogs.com/zhouzhendong/p/AGC027C.html 题解 首先我们假装 max mod min = 1 然后对着这个构造. 将各自黑白染色, ...

  2. AtCoder Grand Contest 012

    AtCoder Grand Contest 012 A - AtCoder Group Contest 翻译 有\(3n\)个人,每一个人有一个强大值(看我的假翻译),每三个人可以分成一组,一组的强大 ...

  3. AtCoder Grand Contest 011

    AtCoder Grand Contest 011 upd:这篇咕了好久,前面几题是三周以前写的... AtCoder Grand Contest 011 A - Airport Bus 翻译 有\( ...

  4. AtCoder Grand Contest 031 简要题解

    AtCoder Grand Contest 031 Atcoder A - Colorful Subsequence description 求\(s\)中本质不同子序列的个数模\(10^9+7\). ...

  5. AtCoder Grand Contest 010

    AtCoder Grand Contest 010 A - Addition 翻译 黑板上写了\(n\)个正整数,每次会擦去两个奇偶性相同的数,然后把他们的和写会到黑板上,问最终能否只剩下一个数. 题 ...

  6. AtCoder Grand Contest 009

    AtCoder Grand Contest 009 A - Multiple Array 翻译 见洛谷 题解 从后往前考虑. #include<iostream> #include< ...

  7. AtCoder Grand Contest 008

    AtCoder Grand Contest 008 A - Simple Calculator 翻译 有一个计算器,上面有一个显示按钮和两个其他的按钮.初始时,计算器上显示的数字是\(x\),现在想把 ...

  8. AtCoder Grand Contest 007

    AtCoder Grand Contest 007 A - Shik and Stone 翻译 见洛谷 题解 傻逼玩意 #include<cstdio> int n,m,tot;char ...

  9. AtCoder Grand Contest 006

    AtCoder Grand Contest 006 吐槽 这套题要改个名字,叫神仙结论题大赛 A - Prefix and Suffix 翻译 给定两个串,求满足前缀是\(S\),后缀是\(T\),并 ...

随机推荐

  1. Spring Boot(九):定时任务

    Spring Boot(九):定时任务 一.pom包配置 pom包里面只需要引入springboot starter包即可 <dependencies> <dependency> ...

  2. Python3 Pandas的DataFrame格式数据写入excle文件、json、html、剪贴板、数据库

    Python3 Pandas的DataFrame格式数据写入excle文件.json.html.剪贴板.数据库 一.DataFrame格式数据 Pandas是Python下一个开源数据分析的库,它提供 ...

  3. 使用dockerfile构建自己的镜像

    CentOS Linux release 7.2.1511 Docker version 17.03.1-ce 首先应该了解docker镜像的分层机制,这个网上文章很多,简单说就是对镜像的每次修改都是 ...

  4. linux检查系统CPU,内存,磁盘使用率

    #!/bin/bash CPU=`top -bn 1 -i -c | sed -n '3p' | awk -F ':' '{print$2}' | awk '{print$1}'` MEM=`free ...

  5. 判断一个点是否在RotatedRect中

    openCV函数pointPolygonTest(): C++: double pointPolygonTest(InputArray contour, Point2f pt, bool measur ...

  6. mysqldump: Couldn't execute 'SHOW VARIABLES LIKE 'ndbinfo_version'': Native table 'performance_schema'.'session_variables' has the wrong structure (1682)

    centos7.5 导出整个数据库报错 问题: [root@db01 ~]# mysqldump -uroot -pBgx123.com --all-databases --single-transa ...

  7. String的getBytes()方法 以及 new String()

    在Java中,String的getBytes()方法是得到一个操作系统默认的编码格式的字节数组.这表示在不同的操作系统下,返回的东西不一样! String.getBytes(Stringdecode) ...

  8. 将svn下载的项目转化为java project

    1.选中项目,右键点击弹出窗口,点击窗口中的[Properties],弹出[Properties for test]窗口, 如下: 2.点击窗口中的[Project Facets],右边显示[Conv ...

  9. 待续未完- 自己写后台内容管理程序 - 用tp框架 和 前台 jquery ui等写的

    在日常开发中,我们主要使用的还是 php 的 内部的 语言本身提供的函数/常量,系统内部数组等. 为了和后面的tp框架提供的 "系统函数.系统常量"相区别,把php提供的东西叫语言 ...

  10. p1110 报表统计(FHQ-TREAP/TREAP)

    平衡树的裸题,操作都相当简单 写了一个FHQ,但是奈何常数太大,实在过不去 最后写了一个Treap开O2水过 TREAP代码 #include <cstdio> #include < ...