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

solution

Posted by khesoem at 2010-07-01 17:17:12 on Problem 3272
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
#include <map>
using namespace std;

int cnt, n, m, d[5000 + 10], db[5000 + 10], arr[5000 + 10], ans;
bool mark[5000 + 10];
vector<int>v[5000 + 10], vb[5000 + 10];
map<pair<int, int>, bool>marke;

int main(){
	memset(mark, 1, sizeof mark);
	scanf("%d %d", &n, &m);
	for(int i = 0; i < m; i++){
		int x, y;
		scanf("%d %d", &x, &y);
		v[x].push_back(y);
		vb[y].push_back(x);
		mark[y] = 0;
	}
	for(int i = 1; i <= n; i++){
		if(mark[i]){
			d[i] = 1;
		}
	}
	for(int i = 1; i <= n; i++){
		for(int j = 0; j < v[i].size(); j++){
			d[v[i][j]] += d[i];
		}
	}
	db[n] = 1;
	for(int i = n; i >= 1; i--){
		for(int j = 0; j < vb[i].size(); j++){
			db[vb[i][j]] += db[i];
			ans = max(ans, d[vb[i][j]] * db[i]);
		}
	}
	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