比赛 2024暑期C班集训1 评测结果 AAAAWWAWWWWWWWWWWWAA
题目名称 熙熙攘攘、我们的城市 最终得分 35
用户昵称 ┭┮﹏┭┮ 运行时间 1.036 s
代码语言 C++ 内存使用 88.70 MiB
提交时间 2024-07-01 10:39:06
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb(x) push_back(x)
#define se second
#define fi first
#define db double
#define pii pair<int,int>
#define pli pair<pair<ll,ll>,int>
#define mp(x,y) make_pair(x,y)
const int N = 1e6+10;
const ll mod = 1e9+7,inf = 1e17;

ll read(){
    ll x = 0,f = 1;char c = getchar();
    for(;c < '0' || c > '9';c = getchar())if(c == '-')f = -1;
    for(;c <= '9' && c >= '0';c = getchar())x = (x<<1) + (x<<3) + c-'0';
    return x * f;
}


int n,m;
int l[N],v[N];
ll t[N];


struct made{
    int ver,nx,id;ll ed;
}e[N<<2];
int hd[N],tot;
void link(int x,int y,ll z,int id){e[++tot] = {y,hd[x],id,z};hd[x] = tot;}


ll d[N];
pli s[N];
bool vi[N];
void dij(int u){
    memset(vi,0,sizeof vi);
    for(int i = 0;i <= n;i++)d[i] = inf;
    priority_queue<pii,vector<pii>,greater<pii> >q;
    q.push(mp(0,u)),d[u] = 0;s[u] = mp(mp(0,0),0);
    while(!q.empty()){
        int x = q.top().se;q.pop();
        if(vi[x])continue;
        vi[x] = 1;
        for(int i = hd[x];i;i = e[i].nx){
            int y = e[i].ver;ll z = e[i].ed;
            if(d[y] > d[x] + z){
                d[y] = d[x] + z;
                if(e[i].id == s[x].se)s[y] = s[x],s[y].fi.se += z;
                else s[y] = mp(mp(s[x].fi.fi+s[x].fi.se*s[x].fi.se,z),e[i].id);
                q.push(mp(d[y],y));
            }
            else if(d[y] == d[x] + z){
                pli sum;
                if(e[i].id == s[x].se)sum = s[x],sum.fi.se += z;
                else sum = mp(mp(s[x].fi.fi+s[x].fi.se*s[x].fi.se,z),e[i].id);
                if(sum.fi.se > s[y].fi.se && sum.fi.fi > s[y].fi.fi)s[y] = sum;
            }
        }
    }
}
void solve(){
    n = read(),m = read();
    for(int i = 1;i <= m;i++){
        l[i] = read();
        for(int j = 1;j <= l[i];j++)v[j] = read(),t[j] = read();
        v[l[i]+1] = read();
        for(int j = 1;j <= l[i];j++)link(v[j],v[j+1],t[j],i);
    }
    dij(1);
    printf("%lld %lld\n",d[n],s[n].fi.fi+s[n].fi.se*s[n].fi.se);
} 
int main(){
    freopen("Wrong_world.in","r",stdin);
    freopen("Wrong_world.out","w",stdout);
    int t = 1;
    while(t--)solve();
    
    return 0;
    
}