Identifying Infected
\quad对于每次查询(a,b),都去循环遍历图中每个点f,假设去掉这个点后a是否还能到b,如果去掉f后a不能到b,则f点一定被感染。这样的话时间复杂度为O(Q∗N∗(N+M))O(Q*N*(N+M))O(Q∗N∗(N+M)),可以过掉30%的数据。
#include <iostream>
#include <queue>
#include <vector>
using namespace std;const int N = 1010;
vector<int> E[N];
int vis[N];
int n, m;
// 看图中是否存在从a到b且不经过f的路径
bool haspath(int a, int b, int f)
{for(int i = 1; i <= n; i ++ ) vis[i] = 0;queue<int> q;q.push(a);vis[a] = 1;while(!q.empty()){int x = q.front();q.pop();if(x == b) return true;for(int y: E[x]){if(vis[y] == 1 || y == f) continue;q.push(y);vis[y] = 1;}}return false;
}int main()
{cin >> n >> m;for(int i = 0; i < m; i ++ ){int u, v; cin >> u >> v;E[u].push_back(v);E[v].push_back(u);}int Q; cin >> Q;while(Q -- ){int u, v; cin >> u >> v;int res = 2;// 依次去掉除了起点和终点的其他点后看看图中是否还存在一条从u到v的路,如果不存在的话则这个点必经过,需要在答案中+1for(int i = 1; i <= n; i ++ )if(i != u && i != v && !haspath(u, v, i)) res ++ ;cout << res << endl;}return 0;
}
Identifying Infected相关推荐
- R语言使用Rtsne包进行TSNE分析:提取TSNE分析结果合并到原dataframe中、可视化tsne降维的结果、并圈定降维后不匹配的数据簇(tSNE identifying mismatch)
R语言使用Rtsne包进行TSNE分析:提取TSNE分析结果合并到原dataframe中.可视化tsne降维的结果.并使用两个分类变量从颜色.形状两个角度来可视化tsne降维的效果.并圈定降维后不匹配 ...
- This subject is anonymous - it does not have any identifying principals and authorization operations
大家好,我是烤鸭: 最近使用shiro,遇到如下问题: 严重: Servlet.service() for servlet [dispatcherServlet] in context with pa ...
- 关于shiro授权 This subject is anonymous - it does not have any identifying principals and authorization
在进行shiro前后分离授权时,报错如下. This subject is anonymous - it does not have any identifying principals and au ...
- Identifying App Installations
Identifying App Installations 30 March 2011 [The contents of this post grew out of an internal discu ...
- ECCV2020 TIDE: A General Toolbox for Identifying Object Detection Errors
ECCV2020 TIDE: A General Toolbox for Identifying Object Detection Errors论文翻译 摘要 1.介绍 2.工具 2.1 计算mAP ...
- 论文笔记:Identifying Lung Cancer Risk Factors in the Elderly Using Deep Neural Network - Chen, Wu
论文笔记:Identifying Lung Cancer Risk Factors in the Elderly Using Deep Neural Network - Chen, Wu 原文链接 I ...
- A-Level经济例题解析及练习 Identifying a firm‘s profit
今日知识点: Identifying a firm's profit 例题 Question: Identifying a firm's profit Determine this firm's to ...
- Identifying Singleton Spammers via Spammer Group Detection
Identifying Singleton Spammers via Spammer Group Detection 目的:识别只发送了一次评论的spammer 探究隐藏的reviewer-produ ...
- Identifying genetic relatives without compromising privacy
文章 He D, Furlotte N A, Hormozdiari F, et al. Identifying genetic relatives without compromising priv ...
最新文章
- 代码工具 | 数据清洗,试试这 8套Python代码
- RISC与CISC比较
- 程序出Bug,一定是环境的锅!
- 2.2 string
- 火狐浏览器添加MetaMask钱包和本地开启私有链开发
- python将数据存入mysql数据库中_python3 两种方法将数据存入mysql数据库
- 一堆数据中将某一个值相同的数据进行分组
- MYSQL端口自动开启的问题~
- 2014.10.1 Form中显示pdf文件
- 常用工具使用(sublimeText)
- win11开热点连接之后无网络解决方案
- 单代号网络图计算例题_海量优质网络图模板,轻巧实用的国产作图神器
- python 绘图英文字体_Python3实现英文字母转换哥特式字体实例代码
- TIMIT语音库下载以及语音库WAV转换相关问题
- fastadmin列表中,时间显示,格式设置
- 2022-2028全球昼夜节律性睡眠障碍行业调研及趋势分析报告
- 蓝桥杯练习题--Fibonacci数列
- 把ipad作为window系统电脑的扩展屏
- 用计算机弹起风了歌词,起风了歌词
- 2016-HitCon-Pwn-house_of_orange学习(附赠FSOP基础知识)