比赛 2024暑期C班集训1 评测结果 AAAAAAAAEAAEEATTTTEE
题目名称 熙熙攘攘、我们的城市 最终得分 55
用户昵称 darkMoon 运行时间 8.239 s
代码语言 C++ 内存使用 104.92 MiB
提交时间 2024-07-01 11:17:11
显示代码纯文本
#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define mp make_pair
using namespace std;
ifstream fin("Wrong_world.in");
ofstream fout("Wrong_world.out");
auto mread = [](){
    int x;
    fin >> x;
    return x;
};
const int N = 1e6 + 5;
int n = mread(), m = mread(), l[N], d[N], p[N], e[N];
vector<pair<int, int> > v[N];
vector<int> a[N], b[N];
signed main(){
    for(int i = 1; i <= m; i ++){
        l[i] = mread();
        for(int j = 1; j <= l[i]; j ++){
            a[i].push_back(mread());
            b[i].push_back(mread());
        }
        a[i].push_back(mread());
        for(int j = 0; j < l[i]; j ++){
            int sum = 0;
            for(int k = j + 1; k < l[i] + 1; k ++){
                sum += b[i][k - 1];
                v[a[i][j]].push_back(mp(a[i][k], sum));
            }
        }
    }
    memset(d, 0x3f, sizeof(d));
    d[1] = 0, p[1] = 0;
    int x = 1;
    while(1){
        e[x] = 1;
        for(auto t : v[x]){
            int y = t.fi, w = t.se;
            if(d[x] + w < d[y]){
                d[y] = d[x] + w;
                p[y] = p[x] + w * w;
            }
            else if(d[x] + w == d[y] && p[x] + w * w > p[y])
            p[y] = p[x] + w * w;
        }
        int tmp = 0, mi = LONG_LONG_MAX;
        for(int i = 1; i <= n; i ++){
            if(e[i] == 0 && d[i] < mi)
            tmp = i, mi = d[i];
        }
        if(tmp == 0)
        break;
        x = tmp;
    }
    fout << d[n] << " " << p[n];
    return 0;
}