当前位置:网站首页>[training Day8] [luogu_p6335] staza [tarjan]
[training Day8] [luogu_p6335] staza [tarjan]
2022-07-24 20:10:00 【VL——MOESR】

Ideas :
We set up fi Indicates the current downward link , Walk back i Maximum path to
gi It means going down at the current point , Don't walk back i Maximum path to
set up w=gi-fi, that gi=fi+w
If i To j The side of is not in the ring , That obviously won't be right fi Contribute to , So let's finish everything first fi, Then go down gj, therefore w=gi+fi+1-fi, Take all the maximum
Then if i To j It's in the ring , Then go through every point in the ring first , Put their f All finished ( This is obviously the biggest ), Contribution: u. Then set v It means that you go to a certain point in the process of walking and don't continue , Instead, it's the one who walks it g, be v=max(dis(i,j)+ ∑ k f k + g j \sum_{k}f_k+g_j ∑kfk+gj),j At which point do you stay ,k yes i Go to the j All passing points . Attention from i To j There are two directions , So we have to calculate . therefore w=max(v-u).
The final answer is g1
c o d e code code
#include<iostream>
#include<cstdio>
using namespace std;
const int MAXN = 1e5 + 10;
int n, m;
int cnt, dfn[MAXN], low[MAXN], f[MAXN], g[MAXN], fa[MAXN];
int tot, head[MAXN];
struct node {
int to, next;
}b[MAXN * 2];
void add(int x, int y) {
b[++ tot] = (node) {
y, head[x] };
head[x] = tot;
}
void tarjan(int x) {
dfn[x] = low[x] = ++ cnt;
int w = 0;
for(int i = head[x]; i; i = b[i].next) {
int y = b[i].to;
if(y == fa[x]) continue;
if(!dfn[y]) {
fa[y] = x;
tarjan(y);
low[x] = min(low[y], low[x]);
if(low[y] > dfn[x]) w = max(w, g[y] + 1);
}
else low[x] = min(low[x], dfn[y]);
}
for(int i = head[x]; i; i = b[i].next) {
int y = b[i].to;
if(dfn[y] > dfn[x] && fa[y] != x) {
int u = 1, v = 0;
for(int k = y; k != x; k = fa[k])
v = max(v, u + g[k]), u += f[k] + 1;
f[x] += u;
int tmp = u;
for(int k = y; k != x; k = fa[k])
tmp -= f[k] + 1, v = max(v, tmp + g[k]);
w = max(w, v - u);
}
}
g[x] = w + f[x];
}
int main() {
scanf("%d%d", &n, &m);
for(int i = 1; i <= m; i ++) {
int x, y;
scanf("%d%d", &x, &y);
add(x, y), add(y, x);
}
tarjan(1);
printf("%d", g[1]);
return 0;
}
边栏推荐
- 147-利用路由元信息设置是否缓存——include和exclude使用——activated和deactivated的使用
- Are network security and data security indistinguishable? Why is data security important?
- Flink window & time principle
- From code farmer to great musician, you only need these music processing tools
- Look at the interface control devaxpress WinForms - how to customize auxiliary function properties (Part 2)
- Solve the problem of error l6218e undefined symbol XXX
- Student achievement management system based on PHP
- Lunch break train & problem thinking: on multidimensional array statistics of the number of elements
- Thymeleaf application notes
- Lunch break train & problem thinking: thinking about the problem of converting the string formed by hour: minute: second to second
猜你喜欢

Machine learning job interview summary: five key points that resume should pay attention to
![Microservice architecture | service monitoring and isolation - [sentinel] TBC](/img/28/8ca90e9dbd492688e50446f55959ff.png)
Microservice architecture | service monitoring and isolation - [sentinel] TBC

Google's display of Chrome browser icons was abandoned, and it was intended to be a small rocket

Setting up a dual machine debugging environment for drive development (vs2017)

Flink window & time principle

Istio II traffic hijacking process

Modbus communication protocol specification (Chinese) sharing

Duilib actual combat 1- imitate Baidu online disk login interface
![[FreeRTOS] 10 event flag group](/img/c3/9f9c2ac4641f478575d48afd580b4b.png)
[FreeRTOS] 10 event flag group

strlen函数剖析和模拟实现
随机推荐
2019 Hangzhou Electric Multi School Game 9 6684 Rikka with game [game question]
Microservice architecture | service monitoring and isolation - [sentinel] TBC
About the largeheap attribute
Rotation matrix derivation process
Basic idea of regularization
Virtual machine win7 system installation vmtool
01 | 开篇词:手把手教你搭建一个博客网站
Interface component devaxpress asp Net v22.1 - new office 365 dark theme
02 | environment preparation: how to install and configure a basic PHP development environment under windows?
Unit DLU of resource editor
Redis basic knowledge, application scenarios, cluster installation
Sword finger offer 53 - I. find the number I in the sorted array
Sword finger offer 48. the longest substring without repeated characters
Look at the interface control devaxpress WinForms - how to customize auxiliary function properties (Part 2)
Leetcode 206 reverse linked list, 3 longest substring without repeated characters, 912 sorted array (fast row), the kth largest element in 215 array, 53 largest subarray and 152 product largest subarr
How to view the execution plan of a stored procedure in Youxuan database
Introduction to WDK development 1- basic environment construction and the first driver (VS2010)
Call Baidu AI open platform to realize image and character recognition
Make Huawei router into FTP server (realize upload and download function)
Risk control system, implemented by flink+clickhouse!