Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

默默粘一发AC代码

Posted by yousiki at 2016-07-05 15:41:38 on Problem 3272
#include<iostream>
#include<vector>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
using namespace std;
#define int long long
inline int nextInt(void){
	int res=0;char ch=getchar();
	while(ch<'0'||ch>'9')ch=getchar();
	while(ch<='9'&&ch>='0')res=res*10+ch-'0',ch=getchar();
	return res;
}
const int N=5005,ONE=1;
vector<int> G[N];
int n,m,a[N],b[N],ans;
signed main(void){
	n=nextInt();m=nextInt();
	for(int i=1,x,y;i<=m;i++){
		x=nextInt();y=nextInt();
		G[x].push_back(y);
		G[y].push_back(x);
	}
	for(int i=1;i<=n;i++){
		a[i]=max(a[i],ONE);
		for(int j=0;j<G[i].size();j++)
		if(G[i][j]>i)a[G[i][j]]+=a[i];
	}
	b[n]=ONE;
	for(int i=n;i>=1;i--){
		for(int j=0;j<G[i].size();j++)
		if(G[i][j]<i)b[G[i][j]]+=b[i];
	}
	for(int i=1;i<=n;i++)
		for(int j=0;j<G[i].size();j++)
			if(i<G[i][j])ans=max(ans,a[i]*b[G[i][j]]);
	cout<<ans<<endl;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator