Highway Project

注意long long


Edward, the emperor of the Marjar Empire, wants to build some bidirectional highways so that he can reach other cities from the capital as fast as possible. Thus, he proposed the highway project.

The Marjar Empire has N cities (including the capital), indexed from 0 to N - 1 (the capital is 0) and there are M highways can be built. Building the i-th highway costs Ci dollars. It takes Di minutes to travel between city Xi and Yi on the i-th highway.

Edward wants to find a construction plan with minimal total time needed to reach other cities from the capital, i.e. the sum of minimal time needed to travel from the capital to city i (1 ≤ iN). Among all feasible plans, Edward wants to select the plan with minimal cost. Please help him to finish this task.


Input

There are multiple test cases. The first line of input contains an integer T indicating the number of test cases. For each test case:

The first contains two integers N, M (1 ≤ N, M ≤ 105).

Then followed by M lines, each line contains four integers Xi, Yi, Di, Ci (0 ≤ Xi, Yi < N, 0 < Di, Ci < 105).

Output

For each test case, output two integers indicating the minimal total time and the minimal cost for the highway project when the total time is minimized.

Sample Input
2
4 5
0 3 1 1
0 1 1 1
0 2 10 10
2 1 1 1
2 3 1 2
4 5
0 3 1 1
0 1 1 1
0 2 10 10
2 1 2 1
2 3 1 2
Sample Output
4 3
4 4
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=1e5+10;
#define inf (1ll<<60)

struct AA{
    int y;
    int d;
    int w;
    AA(){}
    AA(int yy,int dd,int ww):y(yy),d(dd),w(ww){}
};

AA aa[N];

vector<AA> v[N];
ll dist[N];
int wei[N];
int vis[N];

void dijkstra(){
    //memset(dist,63,sizeof(dist));
    fill(dist,dist+N,inf);
    memset(vis,0,sizeof(vis));
    dist[0]=0;
    queue<int> q;
    q.push(0);
    vis[0]=true;
    wei[0]=0;
    while(!q.empty()){
        int u=q.front();
        //cout<<u<<endl;
        q.pop();
        //for(auto uu:v[u]){
        for(int i=0;i<v[u].size();i++){
            AA uu=v[u][i];
            if(dist[u]+uu.d<dist[uu.y]){
                dist[uu.y]=dist[u]+uu.d;
              //  cout<<"uu.y:"<<uu.y<<" "<<dist[uu.y]<<endl;
                wei[uu.y]=uu.w;
                if(!vis[uu.y]){
                    q.push(uu.y);
                    vis[uu.y]=true;
                }
            }else if(dist[u]+uu.d==dist[uu.y]){
                wei[uu.y]=min(wei[uu.y],uu.w);
                if(!vis[uu.y]){
                    q.push(uu.y);
                    vis[uu.y]=true;
                }
            }
        }
        vis[u]=false;
    }
}

int main(){
    int n,m;
    //freopen("in.txt","r",stdin);
    int t;
    cin>>t;
    while(t--){
        int n,m;
        cin>>n>>m;
        for(int i=0;i<=n;i++)
        v[i].clear();
        for(int i=0;i<m;i++){
            int x,y,d,w;
            scanf("%d%d%d%d",&x,&y,&d,&w);
            v[x].push_back(AA(y,d,w));
            v[y].push_back(AA(x,d,w));
        }
        dijkstra();
        ll ans=0,anw=0;
        for(int i=1;i<n;i++){
            ans+=dist[i];
            anw+=wei[i];
           // cout<<"i"<<dist[i]<<" "<<wei[i]<<endl;
        }
        cout<<ans<<" "<<anw<<endl;
    }
    //fclose(stdin);
}
#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define pll pair<ll,ll>
#define plll pair<int,pll>
#define infp (1ll<<60)

const int N=1e5+10;
vector<plll> g[N];

bool vis[N];
pll dis[N];
int n,m;
void spfa(){
    queue<int> q;
    for(int i=0;i<n;i++)
    dis[i]=pll(infp,infp),vis[i]=0;
    q.push(0);
    dis[0]=pll(0,0);
    vis[0]=1;
    while(!q.empty()){
        int u=q.front();
        //cout<<u<<endl;
        for(int i=0;i<g[u].size();i++){
            int v=g[u][i].first;
            int d=g[u][i].second.first;
            int c=g[u][i].second.second;
            if(dis[v]>pll(dis[u].first+d,c)){
                dis[v]=pll(dis[u].first+d,c);
                if(!vis[v]){
                    vis[v]=1;
                    q.push(v);
                }
            }
        }
        vis[u]=0;
        q.pop();
    }
}


int main(){
   // freopen("in.txt","r",stdin);
    int t;
    cin>>t;
    while(t--){
        cin>>n>>m;
        for(int i=0;i<n;i++)
        g[i].clear();
        for(int i=0;i<m;i++){
            int x,y,d,c;
            scanf("%d%d%d%d",&x,&y,&d,&c);
            g[x].push_back(plll(y,pll(d,c)));
            g[y].push_back(plll(x,pll(d,c)));
        }
        spfa();
        ll d=0,c=0;
        for(int i=0;i<n;i++){
            d+=dis[i].first;
            c+=dis[i].second;
        }
        cout<<d<<" "<<c<<endl;
    }
    //fclose(stdin);
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
highway_env是一个用于创建和测试自动驾驶智能体的Python库。它旨在提供一个可扩展的环境,用于开发和评估各种自动驾驶算法。 highway_env提供了一个高速公路环境,其中包括多车道、交通流量、车辆状态和路标等元素。该库提供了一些基本的环境配置选项,例如车道宽度、车辆速度、车辆密度等,以帮助用户创建符合实际情况的测试场景。 在使用highway_env进行自动驾驶智能体开发时,用户可以通过编程和配置文件来设置环境参数,例如目标速度、道路长度、交通流量分布等。智能体可以通过接受环境状态和奖励信号来决定自己的行动,并通过交互与环境进行学习和优化。 高速公路环境中的多车道和交通流量使得智能体需要学习适应不同的交通状况,并在保持安全的同时尽可能快地到达目的地。因此,highway_env非常适合用于测试各种自动驾驶技术的性能和鲁棒性。 此外,highway_env还提供了一系列实用的函数和方法来帮助用户进行环境和智能体参数的配置、数据记录、可视化等。这些功能大大简化了自动驾驶算法的开发和调试过程,提高了开发效率。 总之,highway_env是一个功能强大的Python库,可以提供可扩展的高速公路环境,用于开发和评估自动驾驶智能体。通过使用highway_env,用户可以方便地创建各种测试场景,并进行自动驾驶算法的开发和优化。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值