正文
增加 9 行删除 9 行
44 行未改动4546474849505152533 行未改动575859606162636465666768697071727374757677787980818283848586878889909192937 行未改动1011021031041051061071081092 行未改动11211311411511611711811912012112212312444 行未改动low[u]=min(low[u], low[v]);}else if (!id[v]) low[u]=min(low[u], dfn[v]);}if (low[u]==dfn[u]){cnt++;while (stk.top()!=u) id[stk.top()]=cnt, mn[cnt]=min(mn[cnt], val[stk.top()]), mx[cnt]=max(mx[cnt], val[stk.top()]), stk.pop();3 行未改动void dfs(int u){if (vis[u]) return ;vis[u]=1;for (int i=0; i<b[u].size(); i++) dfs(b[u][i]);}void top(){for (int i=1; i<=cnt; i++) if (!d[i]) q.push(i);while (!q.empty()){int u=q.front();q.pop();for (int i=0; i<c[u].size(); i++){int v=c[u][i];f[v][0]=max(f[v][0], f[u][0]);f[v][1]=max({f[v][1], f[u][0]-mn[v], f[u][1]});f[v][2]=max({f[v][2], f[u][1]+mx[v], f[u][2], mx[v]-mn[v]});d[v]--;if (!d[v]) q.push(v);}}}int main(){// freopen("P1073_16.in", "r", stdin);memset(mn, 63, sizeof mn);scanf("%d%d", &n, &m);for (int i=1; i<=n; i++) scanf("%d", &val[i]);for (int i=1; i<=m; i++){7 行未改动{int v=a[u][j];if (id[u]!=id[v]) b[id[u]].push_back(id[v]);}dfs(id[1]);for (int u=1; u<=n; u++){if (!vis[u]) continue;2 行未改动int v=b[u][j];if (u!=v) c[u].push_back(v), d[v]++;}}for (int i=1; i<=cnt; i++) f[i][0]=f[i][1]=-1000000000;f[id[1]][0]=0, f[id[1]][1]=-mn[id[1]], f[id[1]][2]=mx[id[1]]-mn[id[1]];top();printf("%d", max({f[id[n]][0], f[id[n]][1], f[id[n]][2], 0}));return 0;}```44 行未改动4546474849505152533 行未改动575859606162636465666768697071727374757677787980818283848586878889909192937 行未改动1011021031041051061071081092 行未改动11211311411511611711811912012112212312444 行未改动low[u]=min(low[u], low[v]);}else if (!id[v]) low[u]=min(low[u], dfn[v]);}if (low[u]==dfn[u]){cnt++;while (stk.top()!=u) id[stk.top()]=cnt, mn[cnt]=min(mn[cnt], val[stk.top()]), mx[cnt]=max(mx[cnt], val[stk.top()]), stk.pop();3 行未改动void dfs(int u){if (vis[u]) return ;vis[u]=1;for (int i=0; i<b[u].size(); i++) dfs(b[u][i]);}void top(){for (int i=1; i<=cnt; i++) if (!d[i]) q.push(i);while (!q.empty()){int u=q.front();q.pop();for (int i=0; i<c[u].size(); i++){int v=c[u][i];f[v][0]=max(f[v][0], f[u][0]);f[v][1]=max({f[v][1], f[u][0]-mn[v], f[u][1]});f[v][2]=max({f[v][2], f[u][1]+mx[v], f[u][2], mx[v]-mn[v]});d[v]--;if (!d[v]) q.push(v);}}}int main(){// freopen("P1073_16.in", "r", stdin);memset(mn, 63, sizeof mn);scanf("%d%d", &n, &m);for (int i=1; i<=n; i++) scanf("%d", &val[i]);for (int i=1; i<=m; i++){7 行未改动{int v=a[u][j];if (id[u]!=id[v]) b[id[u]].push_back(id[v]);}dfs(id[1]);for (int u=1; u<=n; u++){if (!vis[u]) continue;2 行未改动int v=b[u][j];if (u!=v) c[u].push_back(v), d[v]++;}}for (int i=1; i<=cnt; i++) f[i][0]=f[i][1]=-1000000000;f[id[1]][0]=0, f[id[1]][1]=-mn[id[1]], f[id[1]][2]=mx[id[1]]-mn[id[1]];top();printf("%d", max({f[id[n]][0], f[id[n]][1], f[id[n]][2], 0}));return 0;}```