UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#183969#1. A+B Problemcmj12345671001ms1188kbC++111.3kb2023-08-09 19:51:492023-08-09 19:51:50

answer

#include<bits/stdc++.h>

using namespace std;
struct node
{
    long long u,v,w,nxt;
}e[5];
struct Queue
{
    long long dis,v;
    bool operator<(const Queue t)const
    {
        return t.dis<dis;
    }
};
long long a,b,head[5],pos,dis[5];
bool vis[5];
priority_queue<Queue> q;
void Insert(long long u,long long v,long long w)
{
    e[++pos]={u,v,w,head[u]};
    head[u]=pos;
}
void Dijkstra(long long u)
{
    memset(dis,0x3f,sizeof(dis));
    memset(vis,false,sizeof(vis));
    q.push({0,u});
    dis[u]=0;
    while(q.size())
    {
        auto cur=q.top();
        q.pop();
        if(vis[cur.v])
            continue;
        vis[cur.v]=true;
        for(int i=head[cur.v];i;i=e[i].nxt)
        {
            if(dis[e[i].v]>dis[cur.v]+e[i].w)
            {
                dis[e[i].v]=dis[cur.v]+e[i].w;
                q.push({dis[e[i].v],e[i].v});
            }
        }
    }
}
long long read()
{
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9')
  {
    if (ch == '-')
      f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
  {
    x = (x << 1) + (x << 3) + (ch ^ 48);
    ch = getchar();
  }
  return x * f;
}
int main()
{
    a=read();
    b=read();
    Insert(1,2,a);
    Insert(2,3,b);
    Dijkstra(1);
    printf("%lld",dis[3]);
    return 0;
}

详细

小提示:点击横条可展开更详细的信息

Test #1:

score: 10
Accepted
time: 0ms
memory: 1184kb

input:

23 24

output:

47

result:

ok 1 number(s): "47"

Test #2:

score: 10
Accepted
time: 0ms
memory: 1184kb

input:

233 1

output:

234

result:

ok 1 number(s): "234"

Test #3:

score: 10
Accepted
time: 0ms
memory: 1188kb

input:

222 333

output:

555

result:

ok 1 number(s): "555"

Test #4:

score: 10
Accepted
time: 0ms
memory: 1188kb

input:

1 333

output:

334

result:

ok 1 number(s): "334"

Test #5:

score: 10
Accepted
time: 0ms
memory: 1184kb

input:

222 333

output:

555

result:

ok 1 number(s): "555"

Test #6:

score: 10
Accepted
time: 0ms
memory: 1188kb

input:

242 333

output:

575

result:

ok 1 number(s): "575"

Test #7:

score: 10
Accepted
time: 1ms
memory: 1184kb

input:

222 3330

output:

3552

result:

ok 1 number(s): "3552"

Test #8:

score: 10
Accepted
time: 0ms
memory: 1184kb

input:

2220 333

output:

2553

result:

ok 1 number(s): "2553"

Test #9:

score: 10
Accepted
time: 0ms
memory: 1188kb

input:

222 555

output:

777

result:

ok 1 number(s): "777"

Test #10:

score: 10
Accepted
time: 0ms
memory: 1188kb

input:

222 3333

output:

3555

result:

ok 1 number(s): "3555"

Extra Test:

score: 0
Extra Test Passed