比赛 2024暑期C班集训1 评测结果 AAAATTATTTTTTTTTTTTT
题目名称 熙熙攘攘、我们的城市 最终得分 25
用户昵称 liuyiche 运行时间 15.196 s
代码语言 C++ 内存使用 74.40 MiB
提交时间 2024-07-01 11:07:20
显示代码纯文本
#include <bits/stdc++.h>
                
using namespace std;

typedef long long ll;

int n, m, Min = 0;
ll Max = 0;

struct node
{
    vector<int> nex;
    vector<int> cost;
    vector<int> id;
};
vector<node> v(1000005); 

inline void dfs(int step, int cnt, ll q, int ltid, ll tmp)
{
    if(cnt > Min)
        return;
    if(step == n)
    {
        q += tmp*tmp;
        if(cnt < Min)
        {
            Min = cnt;
            Max = q;
        }
        else if(cnt == Min && q > Max)
            Max = q;
        return;
    }
    for(int i = 0; i < v[step].nex.size(); ++i)
    {
        int x = v[step].nex[i], id = v[step].id[i], w = v[step].cost[i];
        if(id == ltid)
            dfs(x,cnt+w,q,id,tmp+w);
        else 
            dfs(x,cnt+w,q+tmp*tmp,id,w);
    }
}
        
int main()
{
    freopen("Wrong_world.in", "r", stdin);
    freopen("Wrong_world.out", "w", stdout);
            
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    
    cin >> n >> m;
    for(int i = 1; i <= m; ++i)
    {
        int l, las;
        cin >> l >> las;
        for(int j = 1; j <= l; ++j)
        {
            int u, x;
            cin >> u >> x;
            v[las].nex.push_back(x);
            v[las].cost.push_back(u);
            v[las].id.push_back(i);
            las = x;
            Min += u;
        }
    }
    
    dfs(1,0,0,0,0);
    
    cout << Min << " " << Max;
   	return 0;
}