当前位置: 首页 > news >正文

ABC 454 C - Straw Millionaire 题解

30分钟差点就A三道了没重构出来

solve

  • 写题解表示红温
  • 观察题目,发现呈A->B,所以直接掏出链式前向星建边
  • 搜就完了
  • 贴两份我15写的抽象代码

Code_AC

#include<bits/stdc++.h>
using namespace std;
const int maxn=3e5+10;
int n,m,ans;
int h[maxn],to[maxn],nxt[maxn],tot;
void add(int x,int y)
{tot++;to[tot]=y;nxt[tot]=h[x];h[x]=tot;
}
bool v[maxn];
void dfs(int x)
{if (v[x]) return;v[x]=1;for (int i=h[x];i;i=nxt[i]){int y=to[i];if (!v[y]) dfs(y);}return ;
}
int main()
{cin >> n >> m;for (int i=1;i<=m;i++){int x,y;cin >> x >> y;add(x,y);}dfs(1);for (int i=1;i<=n;i++) if (v[i]) ans++;cout << ans << endl;return 0;
}

Code_TLE/MLE

#include<bits/stdc++.h>
using namespace std;
const int maxn=3e5+10;
int n,m;
int h[maxn],to[maxn],nxt[maxn],tot;
void add(int x,int y)
{tot++;to[tot]=y;nxt[tot]=h[x];h[x]=tot;
}
bool v[maxn];
void dfs(int x)
{for (int i=h[x];i;i=nxt[i]){int y=to[i];if (!v[y]) dfs(y);v[y]=1;}return ;
}
int main()
{cin >> n >> m;for (int i=1;i<=m;i++){int x,y;cin >> x >> y;add(x,y);}dfs(1);int ans=1;for (int i=1;i<=n;i++) if (v[i]) ans++;cout << ans;return 0;
}
  • 亖因:递归后标记

Code_WA

#include<bits/stdc++.h>
using namespace std;
const int maxn=3e5+10;
int n,m;
struct node
{int a,b;
}e[maxn];
bool cmp(node nd1,node nd2)
{return nd1.a<nd2.a;
}
bool v[maxn];
int main()
{cin >> n >> m;for (int i=1;i<=m;i++) cin >> e[i].a >> e[i].b;sort(e+1,e+1+m,cmp);v[1]=1;for (int i=1;i<=m;i++){if (v[e[i].a]) v[e[i].b]=1;}int ans=0;for (int i=1;i<=n;i++){if (v[i]) ans++;}cout << ans << endl;return 0;
}
  • 亖因:诡异代码
http://www.jsqmd.com/news/662736/

相关文章:

  • Pixie语言入门指南:快速掌握这个轻量级魔法Lisp
  • 114
  • 别再折腾路由器了!用闲置树莓派打造低成本、高可靠的WOL远程开机服务器
  • CLIP ViT-H-14镜像免配置部署教程:7860端口Web界面快速启动详解
  • Advanced Tables 社区贡献指南:如何参与项目开发与改进
  • 终极Typhoeus常见问题解决手册:从超时设置到代理配置的完整指南
  • LVGL (7) 显示驱动与缓冲区配置实战
  • 从零到一:手把手教你用EISeg标注数据并训练Mask R-CNN模型
  • 2026年3月质量好的引纸绳生产商推荐,卷钢吊具/吊具/抛缆绳/捆绑索具/链条吊具/无接头钢丝绳,引纸绳厂家哪里有卖 - 品牌推荐师
  • material-ripple未来展望:虽然项目已废弃,但技术思想依然值得学习
  • 如何快速掌握MCP协议标准化进程:Awesome-MCP-ZH最新规范解读
  • DeepBlueCLI输出格式详解:JSON、CSV、HTML等数据处理技巧
  • 告别重复劳动:用VBS脚本与定时执行专家实现键盘鼠标自动化
  • 牛客:狩影.进击
  • [嵌入式系统-259]:RT-Thread消息队列与邮箱的区别
  • Practical.CleanArchitecture中的模块化单体设计:如何实现代码的解耦与复用?
  • fb.resnet.torch图像增强技术详解:提升模型泛化能力的关键
  • 从近场到远场:RFID负载调制与反向散射调制的通信原理与应用场景解析
  • 终极指南:如何参与GildedRose-Refactoring-Kata社区贡献与翻译工作
  • ZeroPoint Security red team ops I CRTO 8 Privilege Escalation 提权
  • Evaluate 未来展望:AI评估工具的发展趋势
  • Kylin V10 /UOS V20下 MySQL open_files_limit 容器内存占用异常的问题处理手册
  • watchfiles实战:如何构建企业级代码热重载系统
  • 2026年3月,解析市面上头部欧宝A14net汽车增压器厂家,卡特增压器/纽荷兰增压器,汽车增压器组件推荐 - 品牌推荐师
  • 2026年美国投资移民项目推荐公司选择指南 - 品牌排行榜
  • 类和对象
  • 从Ptolemaic到Copernican模型:Statistical Rethinking 2023中的模型进化
  • Rust的#[derive(Hash, PartialEq, Eq)]派生宏一致性要求与自定义实现
  • 企业级API网关的功能扩展与流量控制策略实现
  • 如何用Python脚本实现大麦网智能抢票:3分钟快速配置完整指南