题意有点恶心,总结为: 每个点有一个值,这个值的定义是 这个点的度数(也就是有几个点跟他连着) * 从这个点往后找连着的编号递减的链长度
度数好算,输入时出现的次数就是度,,至于编号递减的链 在建边的时候建成有向边,从编号大的指向小的,
本来想跑dfs,后来发现从小的编号开始,直接一个递推过程就算完了
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<stack>
#include<map>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 7, INF = 0x7f7f7f7f, mod = 1e9 + 7;
int n, m;
vector <int> vec[maxn];
int g[maxn] = {0}, len[maxn];
void init() {
scanf("%d %d", &n, &m);
for(int i = 0; i < m; ++i) {
int u, v;
scanf("%d %d", &u, &v);
g[u]++; g[v]++;
if(u > v) {
vec[u].push_back(v);
}
else {
vec[v].push_back(u);
}
}
}
int dfs(int id, int cnt) {
int ans = cnt;
for(int i = 0; i < vec[id].size(); ++i) {
ans = max(ans, len[vec[id][i]]);
}
return ans+1;
}
void solve() {
ll ans = 0LL;
memset(len, 0, sizeof len);
for(int i = 1; i <= n; ++i) {
len[i] = dfs(i, 0);
ans = max(ans, (ll)g[i] * (ll)len[i]);
//cout << " == " << g[i] << " " << len[i] << " == " << endl;
}
cout << ans << endl;
}
int main() {
init();
solve();
return 0;
}