去重!不然有环就直接挂掉了...0分

#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue> using namespace std;
typedef long long ll;
const int maxn=1e3+;
const int maxm=1e4+;
int n,m;
bool vis[maxn][maxn];
struct edge{
int to;
int nxt;
}e[maxm];
int head[maxn];
int tot=;
void init(){
memset(head,-,sizeof(head));
tot=;
}
void add(int u,int v){
e[tot].to=v;
e[tot].nxt=head[u];
head[u]=tot++;
}
void dfs(int fa,int u){
for(int i=head[u];i!=-;i=e[i].nxt){
int v=e[i].to;
if(vis[fa][v]) continue;
vis[fa][v]=true;
dfs(fa,v);
}
}
int work(){
memset(vis,false,sizeof(vis));
for(int i=;i<=n;i++) vis[i][i]=true;
for(int i=;i<=n;i++){
dfs(i,i);
}
// for(int i=1;i<=n;i++){
// for(int j=1;j<=n;j++){
// cout<<vis[i][j]<<" ";
// }
// cout<<endl;
// }
int ans=;
for(int i=;i<=n;i++){
int cnt=;
for(int j=;j<=n;j++){
if(i==j) continue;
if(vis[i][j]) cnt++;
else if(vis[j][i]) cnt++;
}
if(cnt==n) ans++;
}
return ans;
}
int main(){
while(~scanf("%d%d",&n,&m)){
init();
int u,v;
for(int i=;i<=m;i++){
scanf("%d%d",&u,&v);
add(u,v);
}
int ans=work();
printf("%d\n",ans);
}
return ;
}

【CCF】通信网络 简单搜索的更多相关文章

  1. CCF(通信网络):简单DFS+floyd算法

    通信网络 201709-4 一看到题目分析了题意之后,我就想到用floyd算法来求解每一对顶点的最短路.如果一个点和任意一个点都有最短路(不为INF),那么这就是符合的一个答案.可是因为题目超时,只能 ...

  2. CCF CSP 201709-4 通信网络

    CCF计算机职业资格认证考试题解系列文章为meelo原创,请务必以链接形式注明本文地址 CCF CSP 201709-4 通信网络 问题描述 某国的军队由N个部门组成,为了提高安全性,部门之间建立了M ...

  3. ccf认证 201709-4 通信网络 java实现

    试题编号:                                                               201709-4 试题名称: 通信网络 时间限制: 1.0s 内 ...

  4. 通信网络 ccf

    试题编号: 201709-4 试题名称: 通信网络 时间限制: 1.0s 内存限制: 256.0MB 问题描述: 问题描述 某国的军队由N个部门组成,为了提高安全性,部门之间建立了M条通路,每条通路只 ...

  5. solr简单搜索案例

    solr简单搜索案例 使用Solr实现电商网站中商品信息搜索功能,可以根据关键字搜索商品信息,根据商品分类.价格过滤搜索结果,也可以根据价格进行排序,实现分页. 架构分为: 1. solr服务器 2. ...

  6. 分布式搜索ElasticSearch构建集群与简单搜索实例应用

    分布式搜索ElasticSearch构建集群与简单搜索实例应用 关于ElasticSearch不介绍了,直接说应用. 分布式ElasticSearch集群构建的方法. 1.通过在程序中创建一个嵌入es ...

  7. 小dai浅谈通信网络(一)——引子

    说起通信网络,首先来看一个场景: 场景模式: 小明和小刚在闹市碰面. 小明对小刚大声喊道:"小刚,你好啊!" 小刚摇手答到:"你好,小明!" 就这么几句简单的话 ...

  8. 和我一起打造个简单搜索之ElasticSearch集群搭建

    我们所常见的电商搜索如京东,搜索页面都会提供各种各样的筛选条件,比如品牌.尺寸.适用季节.价格区间等,同时提供排序,比如价格排序,信誉排序,销量排序等,方便了用户去找到自己心里理想的商品. 站内搜索对 ...

  9. 通信网络 2G 3G 4G 和路由器2.4G 5G的区分和关系

    通信网络 2G 3G 4G 和路由器2.4G 5G的区分和关系 作者:魔仙圆缘链接:https://www.zhihu.com/question/34076333/answer/57850104来源: ...

随机推荐

  1. How to install Eclipse?

    http://askubuntu.com/questions/26632/how-to-install-eclipse How to install Eclipse? up vote113down v ...

  2. 洛谷 P1926 小书童——刷题大军

    题目背景 数学是火,点亮物理的灯:物理是灯,照亮化学的路:化学是路,通向生物的坑:生物是坑,埋葬学理的人. 文言是火,点亮历史宫灯:历史是灯,照亮社会之路:社会是路,通向哲学大坑:哲学是坑,埋葬文科生 ...

  3. gunzip

    gunzip——解压缩.gz的压缩文件 GNU unzip 命令所在路径:/bin/gunzip 示例1: # gunzip services.gz 解压缩当前目录下的services.gz文件,执行 ...

  4. ubuntu16.0 安装 openstack

    主要参考官方文档:https://docs.openstack.org/liberty/zh_CN/install-guide-ubuntu/environment-nosql-database.ht ...

  5. Resize a UIImage the right way

    When deadlines loom, even skilled and experienced programmers can get a little sloppy. The pressure ...

  6. 搭建一个入门springboot工程

    springboot工程搭建(入门案例) 第一步:创建maven工程 第二步:设置项目信息 第三步:默认项目名称,不用改动(第二步已填写)  第三步:在pom.xml中导入依赖 SpringBoot要 ...

  7. 实现类似AOP的封装和配置

    这是张孝祥老师Java进阶讲解中最后一个视频,就是实现类似spring中的AOP的封装和配置,特别特别小型的一个框架雏形,但是spring中的核心思想还是体现出来了,真的厉害,张老师!!! 一.重点知 ...

  8. shell脚本,按字母出现频率降序排序。

    [root@localhost oldboy]# cat file the squid project provides a number of resources toassist users de ...

  9. MySql中引擎

    1. InnoDB 引擎 MySQL 5.5 及以后版本中的默认存储引擎,它的优点如下:灾难恢复性好,支持事务,使用行级锁,支持外键关联,支持热备份. InnoDB引擎中的表,其数据的物理组织形式是簇 ...

  10. Centos忘记密码解决方法

    centos6.8忘记root密码解决方法 重启系统后出现GRUB界面在引导装载程序菜单上,用上下方向键选择你忘记密码的那个系统键入"e" 来进入编辑模式. 接下来你可以看到如下图 ...