栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

poj 2838 Graph Connectivity

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

poj 2838 Graph Connectivity

#include <iostream>#include <cstring>#include <cstdio>#include <cstdlib>#include <algorithm>#include <cmath>using namespace std;typedef long long ll;const int N = 1005;const int M = 20005;struct arr {int y, nex;} g[M * 2];int n, sz, pos[N], q;bool h[N][N], v[N];void init (int x, int y) {// cout<<x<<" "<<y<<endl;g[++ sz].y = y;g[sz].nex = pos[x];pos[x] = sz;}void dfs (int x) {// cout<<x<<" --------"<<endl;v[x] = 1;for (int i = pos[x]; i; i = g[i].nex) {int y = g[i].y;if (v[y] || !h[x][y]) continue ;dfs (y);}}int main(){char c;int x, y;cin >> n >> q;for (int i = 1; i <= q; i ++) {scanf (" %c %d%d", &c, &x, &y);if (c == 'Q') {memset (v, 0, sizeof(v));dfs (x);if (v[y]) printf ("Yn");else printf ("Nn");} else if (c == 'I') {h[x][y] = h[y][x] = 1;init (x, y), init (y, x);} else {h[x][y] = h[y][x] = 0;}}return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/379117.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号