跳到正文

个人记录

atcoder486 2026.11.30

shuxuejitui约 2 分钟
原文
文章信息与版本

文章信息

发布
2026年11月30日
收录
2026年11月30日
更新
2026年11月30日
篇幅
约 2 分钟

版本

  1. v2当前
  2. v1

前言

本次难度2星,十分简单,但是稍微需要一定的思维

题目记录

A_Phonetic Alphabet

B_ Player Substitution

C_Skip Lighting

D_Monsters

E_Increasing Walk

题意

考察算法

图的存储,线性DP,STL的运用,贪心

思路

利用map的性质来存图,保证遍历的都是从小到大递增

完成度

观看一遍官解

感想

我真废物

代码

C++
#include<iostream>
#include<algorithm>
#include<utility>
#include<map>
#include<vector>
using namespace std;
#define int long long
signed main(){
    int t;
    cin>>t;
    while(t--){
        int n,m;
        cin>>n>>m;
        map<int, vector< pair<int,int> > > G;
        //使用map以使得递增
        for(int i=1;i<=m;i++){
            int u,v,c;
            cin>>u>>v>>c;
            G[c].push_back({u,v});
        }
        vector<int> dp(n+1,0);
        for(auto [c,x]:G){
        //auto的是G这个套娃里面的二阶vector那一部分
            map<int,int> ns;
            for(auto[u,v]:x){
            //auto的是上文二阶vector的两个具体的值
                ns[u]=max(ns[u],dp[v]+c);
                ns[v]=max(ns[v],dp[u]+c);
            }
            //所以答案取最大
            for(auto [X,Y]:ns){
                dp[X]=max(dp[X],Y);
            }
        }
        int ans=0;
        for(int i=1;i<=n;i++) ans=max(ans,dp[i]);
        cout<<ans<<"\n";
    }
}
原文