| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
solution#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator