标签:dep xen red end ble max lan mem tput
On another floor of the A.R.C. Markland-N, the young man Simon "Xenon" Jackson, takes a break after finishing his project early (as always). Having a lot of free time, he decides to put on his legendary hacker "X" instinct and fight against the gangs of the cyber world.
His target is a network of nn small gangs. This network contains exactly n−1n−1 direct links, each of them connecting two gangs together. The links are placed in such a way that every pair of gangs is connected through a sequence of direct links.
By mining data, Xenon figured out that the gangs used a form of cross-encryption to avoid being busted: every link was assigned an integer from 00 to n−2n−2 such that all assigned integers are distinct and every integer was assigned to some link. If an intruder tries to access the encrypted data, they will have to surpass SS password layers, with SS being defined by the following formula:
Here, mex(u,v)mex(u,v) denotes the smallest non-negative integer that does not appear on any link on the unique simple path from gang uu to gang vv.
Xenon doesn‘t know the way the integers are assigned, but it‘s not a problem. He decides to let his AI‘s instances try all the passwords on his behalf, but before that, he needs to know the maximum possible value of SS, so that the AIs can be deployed efficiently.
Now, Xenon is out to write the AI scripts, and he is expected to finish them in two hours. Can you find the maximum possible SS before he returns?
The first line contains an integer nn (2≤n≤30002≤n≤3000), the number of gangs in the network.
Each of the next n−1n−1 lines contains integers uiui and vivi (1≤ui,vi≤n1≤ui,vi≤n; ui≠viui≠vi), indicating there‘s a direct link between gangs uiui and vivi.
It‘s guaranteed that links are placed in such a way that each pair of gangs will be connected by exactly one simple path.
Print the maximum possible value of SS — the number of password layers in the gangs‘ network.
3 1 2 2 3
3
5 1 2 1 3 1 4 3 5
10
In the first example, one can achieve the maximum SS with the following assignment:
With this assignment, mex(1,2)=0mex(1,2)=0, mex(1,3)=2mex(1,3)=2 and mex(2,3)=1mex(2,3)=1. Therefore, S=0+2+1=3S=0+2+1=3.
In the second example, one can achieve the maximum SS with the following assignment:
With this assignment, all non-zero mex value are listed below:
Therefore, S=1+2+1+2+1+3=10S=1+2+1+2+1+3=10.
题解就直接看这个视频吧,感觉讲的不错 题解
1 #include <bits/stdc++.h> 2 using namespace std; 3 const int maxn = 3005; 4 struct Node{ 5 int to, next, dis; 6 }edge[maxn << 1]; 7 int cnt0, cnt[maxn][maxn], head[maxn], fa[maxn][maxn]; 8 int n, s, a[maxn], f[maxn][maxn]; 9 void Add(int u, int v){ 10 edge[++cnt0].to = v; 11 edge[cnt0].next = head[u]; 12 head[u] = cnt0; 13 } 14 void Dfs(int rt, int father, int root){ 15 cnt[root][rt] = 1; 16 fa[root][rt] = father; 17 for (int i = head[rt]; i; i = edge[i].next){ 18 int v = edge[i].to; 19 if (v != father) Dfs(v, rt, root), cnt[root][rt] += cnt[root][v]; 20 } 21 } 22 int Solve(int x, int y){ 23 if (x == y) return 0; 24 if (f[x][y] != -1) return f[x][y]; 25 f[x][y] = cnt[y][x] * cnt[x][y] + max(Solve(fa[y][x], y), Solve(x, fa[x][y])); 26 return f[x][y]; 27 } 28 int main(){ 29 memset(f, -1, sizeof(f)); 30 scanf("%d", &n); 31 for (int i = 1; i < n; i++){ 32 int u, v; 33 scanf("%d%d", &u, &v); 34 u--, v--; 35 Add(u, v); 36 Add(v, u); 37 } 38 for (int i = 0; i < n; i++){ 39 Dfs(i, -1, i); 40 } 41 int ans = 0; 42 for (int i = 0; i < n; i++){ 43 for (int j = 0; j < n; j++){ 44 ans = max(ans , Solve(i, j)); 45 } 46 } 47 cout << ans; 48 return 0; 49 }
Codeforces Round #614 (Div. 2) E. Xenon's Attack on the Gangs
标签:dep xen red end ble max lan mem tput
原文地址:https://www.cnblogs.com/ghosh/p/12681053.html