Poj 3275 Ranking the Cows
来源:互联网 发布:java cms系统开源框架 编辑:程序博客网 时间:2024/06/17 06:03
求点与点之间的连通性。
就是拓扑排序之后点与点之间是否相连。拓扑排序后不会出现加了一条边后导致另外两个未知点大小关系确定的情况。可以分类讨论证明。
我求的是孩子个数,一个点所有的孩子都是小于这个点的。所以结果就是总对数减去孩子数。
这个题目卡临接矩阵。。。有点蛋疼
import java.util.*;import java.io.*;import java.math.BigInteger;class edge{int from, to, next;public edge(int a, int b, int c){from=a;to = b;next = c;}}class problem11{int n,m;edge edges[];int header[];int sons[];boolean vis[]; void solver() throws IOException{ BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(reader.readLine()); n = Integer.valueOf(st.nextToken()); m = Integer.valueOf(st.nextToken()); sons = new int[n]; vis = new boolean[n]; header = new int[n]; Arrays.fill(header, -1); edges = new edge[m]; for(int i=0;i<m;i++){ st = new StringTokenizer(reader.readLine()); int a = Integer.valueOf(st.nextToken())-1; int b = Integer.valueOf(st.nextToken())-1; edges[i] = new edge(a,b,header[a]); header[a] = i; } int s = 0; for(int i=0;i<n;i++){ Arrays.fill(vis, false); sons[i] = dfs(i); s += sons[i]; } int total = n*(n-1)/2; System.out.println(total-s); } int dfs(int start){ int s = 0; vis[start] = true; for(int i=header[start];i!=-1;i=edges[i].next){ int to = edges[i].to; if(!vis[to]){ s+=1; s+=dfs(to); } } return s; }}public class Main{ public static void main (String [] args) throws Exception { problem11 p = new problem11(); p.solver(); }}
0 0
- POJ 3275 Ranking The Cows
- poj 3275 Ranking the Cows
- Poj 3275 Ranking the Cows
- poj 3275 Ranking The Cows
- poj 3275 Ranking the Cows 图+BFS
- poj 3275 Ranking the Cows floyd算法
- poj 3275 Ranking the Cows(floyd …
- poj 3275 Ranking the Cows 传递闭包+邻接表优化
- POJ 3275 Ranking the Cows floyd求传递闭包 || bfs
- PKU 3275 Ranking the Cows 最短路 floyd
- bzoj1703[Usaco2007 Mar]Ranking the Cows 奶牛排名
- 【bzoj1703】[Usaco2007 Mar]Ranking the Cows 奶牛排名
- Treats for the Cows POJ
- BZOJ 1703 [Usaco2007 Mar]Ranking the Cows 奶牛排名 bitset优化
- 传递闭包——洛谷P2881 [USACO07MAR]排名的牛Ranking the Cows
- BZOJ 1703 Ranking the Cows 奶牛排名 (传递闭包)
- BZOJ 1703 [Usaco2007 Mar]Ranking the Cows 奶牛排名 Floyd+bitset
- POJ 2387 Til the Cows Come Home
- Git的使用十(从远程库克隆)仅限Mac亲测
- 简单工厂模式(Simple Factory)
- 我的iOS高效编程秘诀—坚持编程习惯
- 分布式Web服务器架构
- 基于Bmob服务的简单聊天(另加语音通知)
- Poj 3275 Ranking the Cows
- 【PCL】x64+VS2013+PCL1.7.2 简便安装与常见LNK2019问题
- Ubuntu安装DevStack最详细步骤
- Attributed String学习笔记
- POJ问题总结
- 高效程序员的七个习惯
- java操作excel
- DBMS_OUTPUT.PUT_LINE开启
- 技术揭秘一:12306是如何实现高流量高并发的关键技术?