poj 3275 Ranking the Cows 搜索
生活随笔
收集整理的這篇文章主要介紹了
poj 3275 Ranking the Cows 搜索
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
題意:給你n個數和m個大小關系,問給出了這些大小關系之后還有多少對數的大小關系不知道。
分析:根據給出的大小關系建有向邊,每次對每個點延有向邊搜索到底,確定該邊的所有連邊關系,最后統計沒有關系的邊對數。
View Code #include <cstdio> #include <cstring> #include <iostream> using namespace std; #define re(i,n) for(int i=0;i<n;i++) #define re1(i,n) for(int i=1;i<=n;i++) const int maxn = 2020 , maxm = 20020; int n , m; bool pan[maxn][maxn] , vis[maxn]; struct Edge{ int v, next; }edge[maxm]; int E,head[maxn]; inline void init() { E = 0 ;memset(head,-1,sizeof(head)); } inline void addedge(int u,int v) {edge[E].v=v;edge[E].next=head[u];head[u]=E++; } void dfs(int p , int u) {pan[p][u] = pan[u][p] = 1;for(int i=head[u];i!=-1;i=edge[i].next) {int v = edge[i].v;if(vis[v]) continue;vis[v] = true;dfs(p , v);} } void solve() {int ans = 0;re1(i,n) { memset(vis,0,sizeof(vis)); dfs(i , i); }re1(i,n) re1(j,n) if(!pan[i][j]) ans ++;printf("%d\n",ans/2); } int main() {while(~scanf("%d%d",&n,&m)) {memset(pan,0,sizeof(pan));init();while(m--) {int u , v ;scanf("%d%d",&u,&v);addedge(u,v);}solve();}return 0; }轉載于:https://www.cnblogs.com/lenohoo/archive/2012/07/05/2578377.html
總結
以上是生活随笔為你收集整理的poj 3275 Ranking the Cows 搜索的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【转载】索引的一些总结
- 下一篇: hdu 2151