Monk and Graph Problem
来源:互联网 发布:淘宝登入密码怎么修改 编辑:程序博客网 时间:2024/05/29 15:37
中文题意:求一个图中的最大连通子图的边的个数。
Monk and his graph problems never end. Here is one more from our own Monk:
Given an undirected graph with N vertices and M edges, what is the maximum number of edges in any connected component of the graph.
In other words, if given graph has k connected components, and E1,E2,....Ek be the number of edges in the respective connected component, then find max(E1,E2,....,Ek) .
The graph may have multiple edges and self loops. The N vertices are numbered as 1,2,...,N.
Input Format:
The first line of input consists of two space separated integers N and M, denoting number of vertices in the graph and number of edges in the graph respectively.
Following M lines consists of two space separated each a and b, denoting there is an edge between vertex a and vertex b.
Output Format:
The only line of output consists of answer of the question asked by Monk.
Input Constraints:
1≤N≤105
0≤M≤105
1≤a,b≤N
6 31 22 34 5
2
The graph has 3 connected components :
First component is 1−2−3 which has 2 edges.
Second component is 4−5 which has 1 edge.
Third component is 6 which has no edges.
So, answer is max(2,1,0)=2
C, C++, C++14, Clojure, C#, D, Erlang, F#, Go, Groovy, Haskell, Java, Java 8, JavaScript(Rhino), JavaScript(Node.js), Julia, Kotlin, Lisp, Lisp (SBCL), Lua, Objective-C, OCaml, Octave, Pascal, Perl, PHP, Python, Python 3, R(RScript), Racket, Ruby, Rust, Scala, Swift, Visual Basic
#include <bits/stdc++.h>#include <vector>using namespace std;vector <int>adj[100005];bool visited[100005];int mmax = 0;int Count=0;void dfs(int s){visited[s] = 1;for (int i = 0; i<adj[s].size(); ++i){ Count++;if (visited[adj[s][i]]== 0)dfs(adj[s][i]);}}int main(){int nodes, edges, x, y;cin >> nodes >> edges;memset(visited, 0, sizeof(visited));for (int i = 0; i<edges; ++i){cin >> x >> y;adj[x].push_back(y);adj[y].push_back(x);}for (int i=0; i <= nodes; ++i){if (!visited[i])dfs(i);mmax=max(mmax,Count/2);Count=0;}cout << mmax << endl;}
- Monk and Graph Problem
- 深度优先搜索 dfs Monk and Graph Problem
- [Haskell on HackerEarth] Monk and Welcome Problem
- [Haskell on HackerEarth] Monk and Digital World
- Graph Theory - Assignment Problem
- uva_11069_A Graph Problem( DP )
- A Graph Problem
- Covisibility Graph and Essential Graph
- Graph and Queries hdu3762
- Graph: basic and traversal
- cf459E Pashmak and Graph
- CF624C - Graph and String
- UVA 11069 - A Graph Problem
- UVA 11069 A Graph Problem
- UVA 11069 A Graph Problem
- UVa 11069 - A Graph Problem
- UVA11069 - A Graph Problem(DP)
- uva 11069A Graph Problem
- 【安全牛学习笔记】手动漏洞挖掘(三)
- 嵌入式实验(二)
- JAVA设计模式:模板设计模式
- sqlite报错 near "group": syntax error
- 第一篇:概述 -- 3.大型网站核心构架要素 笔记
- Monk and Graph Problem
- Python学习---第十二天 git使用知识点积累
- 第6章gp_toolkit管理架构-gp_locks_on_resqueue
- CC:可关联生命周期的android组件化开发框架
- 欢迎使用CSDN-markdown编辑器
- android开发view简单总结
- 【Web Spider】网络爬虫(一):抓取网页的含义和URL基本构成
- 聊一聊 Spring 中的线程安全性
- android 给图片设置滤镜报错OutOfMemoryError