poj 3275 Ranking The Cows
来源:互联网 发布:超级优化李玄 编辑:程序博客网 时间:2024/06/17 20:36
题目大意:
略了。。。。
大概就是邻接矩阵会t的一道题,所以用邻接表优化。
邻接表写跪了。。我的天。。
主要是高低的邻接表。。
#include<cstdio>#include<cstring>#include<algorithm>using namespace std;//by mars_chint c[1005][1005],map[1005][1005];int n,m;struct node{ int f,t,w,nxt;}e[1000005];int tot,first[10005];struct data{ int f,t,w,nxt;}b[1000005];int head[10005],tol;void add1(int a,int b){ e[tot].f=a,e[tot].t=b; e[tot].nxt=first[a]; first[a]=tot++;}void add2(int a,int bb){ e[tot].f=a,e[tot].t=bb; e[tot].nxt=head[a]; head[a]=tot++;}int main(){ memset(first,-1,sizeof(first)); memset(head,-1,sizeof(head)); scanf("%d%d",&n,&m); int ans=n*(n-1)/2; int cnt=0; for(int i=1;i<=m;i++) { int a,b; scanf("%d%d",&a,&b); add1(a,b); add2(b,a); map[a][b]=1; } for(int i=1;i<=n;i++) { for(int j=head[i];j!=-1;j=e[j].nxt) { int a=e[j].t; for(int k=first[i];k!=-1;k=e[k].nxt) { int bb=e[k].t; if(map[a][bb]) continue;// printf("i=%d a=%d bb=%d\n",i,a,bb); map[a][bb]=1; add1(a,bb); add2(bb,a); } } } for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) { if(map[i][j] == 1) { cnt++; } } } printf("%d\n",ans-cnt); return 0;}
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
- 层次凝聚聚类法
- CUDA 纹理内存 Error:无法识别texture
- handy : EventBase, EventsImp, Poller, Channel
- 熟悉自定义View
- XML文件
- poj 3275 Ranking The Cows
- UVA 679Dropping Balls
- caffe的protocol buffer使用例子
- 三星手机在返回上一个界面时,会闪现不该出现的界面
- java设计模式之------策略模式
- maven配置jdk版本
- 常用且实现的JS小插件
- Java SE面试题(经常出现却又容易被忽略的题目)
- 第五周-8三色球问题