Codeforces Round #447 (Div. 2) E DAG+scc (未敲)

本文针对Codeforces上的一道题目E.Ralph and Mushrooms进行详细解析。该题要求在有向图中找到从指定起点出发所能收集的最大蘑菇数量,考虑了边的重复利用及其收益递减特性。文章通过Tarjan算法求强连通分量并将其转化为有向无环图(DAG),最终采用拓扑排序DP的方法求解最值。

参考:http://codeforces.com/blog/entry/55884http://blog.youkuaiyun.com/Icefox_zhx/article/details/78590429
题目:http://codeforces.com/contest/894/problem/E

E. Ralph and Mushrooms

Ralph is going to collect mushrooms in the Mushroom Forest.

There are m directed paths connecting n trees in the Mushroom Forest. On each path grow some mushrooms. When Ralph passes a path, he collects all the mushrooms on the path. The Mushroom Forest has a magical fertile ground where mushrooms grow at a fantastic speed. New mushrooms regrow as soon as Ralph finishes mushroom collection on a path. More specifically, after Ralph passes a path the i-th time, there regrow i mushrooms less than there was before this pass. That is, if there is initially x mushrooms on a path, then Ralph will collect x mushrooms for the first time, x - 1 mushrooms the second time, x - 1 - 2 mushrooms the third time, and so on. However, the number of mushrooms can never be less than 0.

For example, let there be 9 mushrooms on a path initially. The number of mushrooms that can be collected from the path is 9, 8, 6 and 3 when Ralph passes by from first to fourth time. From the fifth time and later Ralph can’t collect any mushrooms from the path (but still can pass it).

Ralph decided to start from the tree s. How many mushrooms can he collect using only described paths?
Input

The first line contains two integers n and m (1 ≤ n ≤ 106, 0 ≤ m ≤ 106), representing the number of trees and the number of directed paths in the Mushroom Forest, respectively.

Each of the following m lines contains three integers x, y and w (1 ≤ x, y ≤ n, 0 ≤ w ≤ 108), denoting a path that leads from tree x to tree y with w mushrooms initially. There can be paths that lead from a tree to itself, and multiple paths between the same pair of trees.

The last line contains a single integer s (1 ≤ s ≤ n) — the starting position of Ralph.
Output

Print an integer denoting the maximum number of the mushrooms Ralph can collect during his route.
Examples

input
2 2
1 2 4
2 1 4
1
output
16
input
3 3
1 2 4
2 3 3
1 3 8
1
output
8
Note

In the first sample Ralph can pass three times on the circle and collect 4 + 4 + 3 + 3 + 1 + 1 = 16 mushrooms. After that there will be no mushrooms for Ralph to collect.

In the second sample, Ralph can go to tree 3 and collect 8 mushrooms on the path from tree 1 to tree 3.

题意

给你n个点m条边的有向图,每条边都会有蘑菇,一开始第i个边有a[i]个蘑菇,第一次经过能获得a[i]个,第二次能获得a[i]-1个,第三次能获得a[i]-1-2个,直到a[i]非负。

现在给你起点,问你最多能获得多少个蘑菇。

一个强连通内的边显然可以把它的价值完全压榨,其他的边只能过一次,所以我们tarjan求scc,缩成DAG,然后拓扑序dp求最长路。至于怎么算一条边的所有价值,数学搞吧。首先求出n∗(n+1)<=w的最大的n,然后价值就是n∗w−∑ni=1i∗(i+1)/2+w,也就是n∗w−n∗(n+1)∗(n+2)/6+w

http://blog.youkuaiyun.com/Dylan_Frank/article/details/78584076


#include <bits/stdc++.h>
using namespace std;
#define ms(x,v) (memset((x),(v),sizeof(x)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF 0x3f3f3f3f
#define INF64 0x3f3f3f3f3f3f3f3f
typedef long long LL;
typedef pair<int,int > Pair;
const int maxn = 1e6 +10;
const int maxv = 1e8+10;
const int MOD = 1e9+7;

LL tmp[maxn],sum[maxn],t=0;
inline LL weight(LL x){
    int p = lower_bound(tmp,tmp+t,x) - tmp-1;
    return x*(p+1) - sum[p];
}
int n,m,s;
LL ans =0;
bool vis[maxn];
LL node[maxn],dp[maxn];//缩点后贡献
//scc
std::vector<int> sc_node[maxn];
std::vector<Pair> G[maxn];
int dfn[maxn],low[maxn];
int dfs_clock=0;
int scc[maxn],scc_cnt=0;
stack<int> S;//辅助栈
void dfs(int u) {
    low[u] = dfn[u] = ++dfs_clock;
    S.push(u);
    for(auto e:G[u]){
         int v = e.fi;
        if(!dfn[v]){
            //未访问
            dfs(v);
            low[u] = min(low[v],low[u]);
        }else if(!scc[v])low[u] = min(low[v],low[u]);
    }
    //计算出low值之后看是否满足起始条件
    if(low[u] == dfn[u]){
        //标记
        scc_cnt++;
        while (true) {
            int v = S.top();S.pop();
            scc[v] = scc_cnt;
            if(v == u)break;
        }
    }
}

LL solve(int u) {
    if(dp[u]!=-1)return dp[u];
    dp[u] = node[u];
    LL ans = 0;
    for(auto v : sc_node[u]){
        for(auto e : G[v])
            if(scc[e.fi] != u){
                ans = max(ans,solve(scc[e.fi])+e.se);
            }
    }
    return dp[u]+=ans;
}

int main(int argc, char const *argv[]) {
     for(t=0; tmp[t-1]<maxv ; ++t)tmp[t] = t+ tmp[t-1],sum[t]=tmp[t]+sum[t-1];
     cin>>n>>m;
     for(int i=0 ; i<m ; ++i){
         int x,y,w;
         scanf("%d%d%d",&x,&y,&w );
         G[x].pb(mp(y,w));
     }
     cin>>s;
     for(int i=1 ; i<=n ; ++i)
        if(!dfn[i])dfs(i);
     for(int i=1 ; i<=n ; ++i){
         sc_node[scc[i]].pb(i);
         for(auto e: G[i]){
             if(scc[e.fi]==scc[i])node[scc[i]]+=weight(e.se);
         }
     }
     ms(dp,-1);
     std::cout << solve(scc[s]) << '\n';
    return 0;
}
传送带损坏与对象检测数据集 一、基础信息 • 数据集名称:传送带损坏与对象检测数据集 • 图片数量: 训练集:645张图片 验证集:185张图片 测试集:92张图片 总计:922张工业监控图片 • 训练集:645张图片 • 验证集:185张图片 • 测试集:92张图片 • 总计:922张工业监控图片 • 分类类别: Hole(孔洞):传送带表面的孔洞损坏。 Human(人类):工作区域中的人类,用于安全监控。 Other Objects(其他对象):非预期对象,可能引起故障。 Puncture(刺穿):传送带被刺穿的损坏。 Roller(滚筒):传送带滚筒部件。 Tear(撕裂):传送带撕裂损坏。 impact damage(冲击损坏):由于冲击导致的损坏。 patch work(修补工作):已修补的区域。 • Hole(孔洞):传送带表面的孔洞损坏。 • Human(人类):工作区域中的人类,用于安全监控。 • Other Objects(其他对象):非预期对象,可能引起故障。 • Puncture(刺穿):传送带被刺穿的损坏。 • Roller(滚筒):传送带滚筒部件。 • Tear(撕裂):传送带撕裂损坏。 • impact damage(冲击损坏):由于冲击导致的损坏。 • patch work(修补工作):已修补的区域。 • 标注格式:YOLO格式,包含边界框和类别标签,适用于目标检测任务。 • 数据格式:图像数据来源于工业监控系统,适用于计算机视觉分析。 二、适用场景 • 工业自动化检测系统开发:用于构建自动检测传送带损坏和异物的AI模型,实现实时监控和预防性维护,减少停机时间。 • 安全监控应用:识别人类和其他对象,提升工业环境的安全性,避免事故和人员伤害。 • 学术研究与创新:支持计算机视觉在制造业、物流和自动化领域的应用研究,促进AI技术与工业实践的融合。 • 教育与培训:可用于培训AI模型或作为工业工程和自动化教育的案例数据,帮助学习者理解实际应用场景。 三、数据集优势 • 多样化的类别覆盖:包含8个关键类别,涵盖多种损坏类型和对象,确保模型能够处理各种实际工业场景,提升泛化能力。 • 精准的标注质量:采用YOLO格式,边界框标注准确,由专业标注人员完成,保证数据可靠性和模型训练效果。 • 强大的任务适配性:兼容主流深度学习框架(如YOLO、TensorFlow、PyTorch),可直接用于目标检测任务,并支持扩展至其他视觉任务需求。 • 突出的工业价值:专注于工业传送带系统的实际需求,帮助提升生产效率、降低维护成本,并增强工作场所安全,具有较高的实际应用价值。
一、基础信息 • 数据集名称:垃圾废弃物目标检测数据集 • 图片数量: 训练集:1124张图片 验证集:375张图片 总计:1499张图片 • 训练集:1124张图片 • 验证集:375张图片 • 总计:1499张图片 • 分类类别:包含60多个垃圾和废弃物类别,如气溶胶、铝泡罩包装、电池、破碎玻璃、卡片泡罩包装、香烟、透明塑料瓶、瓦楞纸箱、薯片袋、一次性食品容器、一次性塑料杯、饮料罐、饮料纸盒、鸡蛋盒、泡沫杯、泡沫食品容器、食品罐、食物垃圾、垃圾袋、玻璃瓶、玻璃杯、玻璃罐、杂志纸、餐盒、金属瓶盖、金属盖、普通纸、其他纸箱、其他塑料、其他塑料瓶、其他塑料容器、其他塑料杯、其他塑料包装、纸袋、纸杯、纸吸管、披萨盒、塑料瓶盖、塑料薄膜、塑料手套、塑料盖、塑料吸管、塑料餐具、聚丙烯袋、拉环、绳子、废金属、鞋子、一次性购物袋、六罐环、涂抹管、可挤压管、泡沫塑料片、纸巾、厕纸管、特百惠、标记垃圾、包装纸等。 • 标注格式:YOLO格式,包含边界框和类别标签,适用于目标检测任务。 • 数据格式:图片来源于实际场景,细节清晰。 二、适用场景 • 垃圾自动分类系统开发:数据集支持目标检测任务,帮助构建能够自动识别和分类垃圾物品的AI模型,用于智能垃圾桶或回收系统,提升废弃物管理效率。 • 环保应用研发:集成至环保和废弃物管理应用,提供实时垃圾识别功能,促进回收和环境保护,支持可持续发展倡议。 • 学术研究与创新:支持计算机视觉与环保领域的交叉研究,助力发表垃圾识别和AI技术相关学术论文,推动技术创新。 • 教育与培训:可用于学校或培训机构,作为垃圾分类和AI目标检测教学的重要资源,培养环保意识和技术能力。 三、数据集优势 • 精准标注与多样性:每张图片经过准确标注,确保边界框定位精确;包含多种垃圾类别,覆盖常见废弃物,提升模型的泛化能力和鲁棒性。 • 任务适配性强:标注兼容主流深度学习框架(如YOLO等),可直接用于目标检测任务,并支持扩展到其他视觉任务,如分类或分割。 • 实际应用价值:专注于垃圾识别,为环保、废弃物管理和回收提供重要数据支撑,有助于减少污染和促进循环经济。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值