栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

poj 3272 Cow Traffic

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

poj 3272 Cow Traffic

#include<cstdio>#include<cstring>#include<algorithm>using namespace std;const int N=5005;typedef long long ll;int head[2][N],nc[2];ll tot[2][N];bool flag[N];struct Edge{    int to,next;}edge[2][N*20];void add(int a,int b,int k){    edge[k][nc[k]].to=b;edge[k][nc[k]].next=head[k][a];head[k][a]=nc[k]++;}int main(){    int n,m;    while(scanf("%d%d",&n,&m)!=EOF)    {        memset(head,-1,sizeof(head));        memset(tot,0,sizeof(tot));        memset(flag,false,sizeof(flag));        nc[0]=nc[1]=0;        for(int i=0,a,b;i<m;i++)        { scanf("%d%d",&a,&b); add(a,b,0); add(b,a,1); flag[b]=true;        }        ll ans=0;        for(int i=1;i<=n;i++)        { if(!flag[i])     tot[0][i]=1; for(int j=head[0][i];j!=-1;j=edge[0][j].next)     tot[0][edge[0][j].to]+=tot[0][i];        }        tot[1][n]=1;        for(int i=n;i>=1;i--)        { for(int j=head[1][i];j!=-1;j=edge[1][j].next)     tot[1][edge[1][j].to]+=tot[1][i];        }        for(int i=1;i<=n;i++) for(int j=head[0][i];j!=-1;j=edge[0][j].next)     ans=max(ans,tot[0][i]*tot[1][edge[0][j].to]);        printf("%lldn",ans);    }    return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/372032.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号