为啥这dijkstra的a+b问题只有九十分??

P1001 A+B Problem

lmn985 @ 2024-04-19 20:19:05


#include <bits/stdc++.h>
#define ll long long
#define MP make_pair
#define pa pair<int,int>
#define dijk priority_queue
const int N=2e5+1;
using namespace std;
int d[N],x,y;
vector<int> a[N];
map<int,map<int,int> > cost;
void dijkstra(){
    memset(d,0x3f,sizeof(d));
    d[1]=0;
    dijk<pa, vector<pa>, greater<pa> > w;
    w.push(MP(0,1));
    while(!w.empty()){
        pa x=w.top();w.pop();
        ll rt=x.second;
        if(d[x.second]>=x.first)
        for(int i=0;i<a[rt].size();i++)
        if(d[rt]+cost[rt][a[rt][i]]<d[a[rt][i]]){
            d[a[rt][i]]=d[rt]+cost[rt][a[rt][i]];
            w.push(MP(d[a[rt][i]],a[rt][i]));
        }
    }
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie();
    cin>>x>>y;
    a[1].push_back(2);
    cost[1][2]=x;
    a[2].push_back(3);
    cost[2][3]=y;
    dijkstra();
    cout<<d[3];
    return 0;
}

by luochenkai @ 2024-04-20 11:21:35

有没有可能int装得下?


by luochenkai @ 2024-04-20 11:22:16

#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b;
    cin>>a>>b;
    cout<<a+b;
    return 0;
}

by GeorgeCHN @ 2024-04-25 15:14:47

这是简单A+B,不用高精!

(求关注!)


by GeorgeCHN @ 2024-04-25 15:22:34

我给你关注了哈


by __little__Cabbage__ @ 2024-04-27 10:02:47

@GeorgeCHN 人家想写就写


by GeorgeCHN @ 2024-04-27 10:11:42

@littleCabbage__ 我能高精一百分,TA不行的话建议别作死


by aochiao @ 2024-05-01 17:40:36

@lmn985 P2142才要高进度,这里不需要。


#include<bits/stdc++.h>
using namespace std;
int main(){
    long long a,b;
    cin >>a >>b;
    cout <<a+b;
    return 0;
}

by yiming_328 @ 2024-05-02 20:58:03

@lmn985 因为dij不能处理负边


by yiming_328 @ 2024-05-02 20:59:05

@GeorgeCHN 这是最短路,不是高精


by Ascnbeta @ 2024-07-18 10:49:55

《论dij可以处理负数这件事》


|