UVALive 6907Body Building(暴力)
来源:互联网 发布:模拟考试软件 编辑:程序博客网 时间:2024/06/13 09:50
题意:
N≤100的图,问哑铃形有几个,哑铃形指的是一个连通分量,且由唯一的桥相连的两个图形是点数相等的完全图
分析:
tarjan找出所有的桥,测试两边的图形是否是完全图,看点数是否相等以及边数是否完全
不找桥直接暴力枚举边也可,O(n3)也可以通过
不能通过每个点度来判断完全图,有反例,没有什么比搜一下更靠谱了
代码:
//// Created by TaoSama on 2015-12-21// Copyright (c) 2015 TaoSama. All rights reserved.////#pragma comment(linker, "/STACK:1024000000,1024000000")#include <algorithm>#include <cctype>#include <cmath>#include <cstdio>#include <cstdlib>#include <cstring>#include <iomanip>#include <iostream>#include <map>#include <queue>#include <string>#include <unordered_set>#include <set>#include <vector>using namespace std;#define pr(x) cout << #x << " = " << x << " "#define prln(x) cout << #x << " = " << x << endlconst int N = 1e2 + 10, INF = 0x3f3f3f3f, MOD = 1e9 + 7;int n, m;vector<int> G[N];bool vis[N];void dfs(int u, int f, int &sz, int &sum) { ++sz; sum += G[u].size(); vis[u] = true; for(int v : G[u]) { if(v == f || vis[v]) continue; dfs(v, f, sz, sum); }}bool test(int u, int v) { memset(vis, false, sizeof vis); int sz1 = 0, sum1 = 0; dfs(u, v, sz1, sum1); memset(vis, false, sizeof vis); int sz2 = 0, sum2 = 0; dfs(v, u, sz2, sum2); return sz1 == sz2 && sum1 == sum2 && sum1 == sz1 * (sz1 - 1) + 1;}int main() {#ifdef LOCAL freopen("C:\\Users\\TaoSama\\Desktop\\in.txt", "r", stdin);// freopen("C:\\Users\\TaoSama\\Desktop\\out.txt","w",stdout);#endif ios_base::sync_with_stdio(0); int t; scanf("%d", &t); while(t--) { scanf("%d%d", &n, &m); for(int i = 1; i <= n; ++i) G[i].clear(); while(m--) { int u, v; scanf("%d%d", &u, &v); G[u].push_back(v); G[v].push_back(u); } int ans = 0; for(int u = 1; u <= n; ++u) for(int v : G[u]) ans += test(u, v); static int kase = 0; printf("Case #%d: %d\n", ++kase, ans >> 1); } return 0;}
0 0
- UVALive 6907Body Building(暴力)
- UVALive 6852Blanket(暴力)
- UVALive 6895Deduction(暴力)
- UVA 6907 Body Building Tarjan找桥
- UVALive 6089 Nine (暴力模拟)
- UVALive - 5908(UVA1517)Tracking RFIDs(暴力)
- UVALive 6621 Pocket Cube(暴力)
- Body Building(求割边)
- hdu 4584 Building bridges(暴力搜索)
- hdu4584 Building bridges(暴力枚举)
- HDU 5538 House Building(分类暴力)
- UVALive - 2963 Hypertransmission 暴力
- uvalive 4253(暴力)
- UVALive - 4253 Archery 暴力
- UVALive 6924 暴力
- UVALive 7279 Sheldon Numbers(位运算、暴力、想法)
- UVALive 6843Volume Control(暴力压位)
- 【UVALive】2037 - Digital Rivers(找规律,暴力)
- OC1
- 教你5种JSP页面显示为乱码的解决方法
- 【朝花夕拾】C语言-空白与注释
- LevelDb日知录之八:Compaction
- oracle用户名以及口令忘记了咋办?
- UVALive 6907Body Building(暴力)
- LeetCode 11 - Container With Most Water
- is not in the sudoers file 解决
- OC2
- java并发编程学习之一段简单代码证明synchronized锁的是对象
- ListView "Cannot add header view to list -- setAdapter has already been called."
- SSL 1344 Knights 最大匹配
- java实现简单的单链表结构
- 61.简单实用iCarousel(第三方类库)和毛玻璃效果