QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#448981 | #4171. 魔法猪学院 | QWQcoding | 100 ✓ | 107ms | 43716kb | C++14 | 1.6kb | 2024-06-20 15:28:49 | 2024-06-20 15:28:49 |
Judging History
answer
#include<bits/stdc++.h>
#define re register
#define N 5009
#define M 400009
#define in read()
using namespace std;
inline int read(){
char ch;int f=1,res=0;
while((ch=getchar())<'0'||ch>'9') if(ch=='-') f=-1;
while(ch>='0'&&ch<='9'){
res=(res<<3)+(res<<1)+ch-'0';
ch=getchar();
}
return f==1?res:-res;
}
int n,m,S,T,ans;
double tot,dis[N];
struct node{int u;double cost;};
bool operator <(const node &a,const node &b){
return dis[a.u]+a.cost>dis[b.u]+b.cost;
}
int nxt[M],to[M],head[N],cnt=0;
double w[M];
void add(int x,int y,double z){
nxt[++cnt]=head[x];head[x]=cnt;to[cnt]=y;w[cnt]=z;
}
int Nxt[M],To[M],Head[N],Cnt=0;
double W[M];
void conadd(int x,int y,double z){
Nxt[++Cnt]=Head[x];Head[x]=Cnt;To[Cnt]=y;W[Cnt]=z;
}
bool vis[N];
void spfa(){
memset(dis,127,sizeof(dis));
queue<int > q;q.push(S);dis[S]=0;
while(!q.empty()){
int u=q.front();q.pop();vis[u]=0;
for(int e=Head[u];e;e=Nxt[e]){
int v=To[e];
if(dis[v]>dis[u]+W[e]){
dis[v]=dis[u]+W[e];
if(!vis[v]) q.push(v),vis[v]=1;
}
}
}
}
priority_queue<node> que;
void Astar(){
que.push((node){S,0});
while(!que.empty()){
node now=que.top();que.pop();
if(now.u==T){
tot-=now.cost;
if(tot<0) return;
ans++;
continue;
}
for(int e=head[now.u];e;e=nxt[e]){
int v=to[e];
que.push((node){v,now.cost+w[e]});
}
}
}
int main(){
n=in;m=in;scanf("%lf",&tot);
int u,v,i,j,k;
double len;
for(i=1;i<=m;++i){
u=in;v=in;scanf("%lf",&len);
conadd(v,u,len);add(u,v,len);
}
S=n;T=1;
spfa();//处理出估价函数dis
ans=0;
S=1;T=n;
Astar();
cout<<ans;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 10
Accepted
time: 1ms
memory: 5860kb
input:
6 14 66666 3 4 31210.2 4 5 11207.2 5 2 19087.1 1 3 25736.9 2 6 10925.6 5 2 20617.1 2 4 8577.14 1 5 7859.54 4 6 29233.4 3 2 5416.09 2 5 10870.9 5 4 8595.81 6 3 30738.3 4 1 4210.31
output:
1
result:
ok single line: '1'
Test #2:
score: 10
Accepted
time: 1ms
memory: 9960kb
input:
30 96 100 9 26 4 26 22 5 22 10 6 10 6 7 6 21 9 21 11 4 11 17 10 17 2 10 2 18 9 18 28 5 28 4 9 4 29 6 29 25 8 25 20 6 20 14 10 14 5 5 5 23 7 23 15 6 1 9 7 15 30 10 16 24 10 24 9 7 9 21 3 21 10 3 10 7 3 7 18 9 18 20 10 20 12 3 12 27 8 27 3 4 3 23 4 23 28 10 28 8 4 8 15 3 15 17 3 17 5 4 5 6 10 6 2 6 2 ...
output:
4
result:
ok single line: '4'
Test #3:
score: 10
Accepted
time: 1ms
memory: 10208kb
input:
99 641 99 42 5 7 5 14 6 14 11 8 11 77 4 77 36 5 36 86 2 86 93 7 93 97 2 97 50 3 50 76 5 76 3 4 3 61 3 61 96 4 96 45 6 45 72 7 72 67 9 67 39 7 39 35 3 35 54 8 54 75 6 75 38 7 38 66 3 66 88 8 88 92 6 92 80 2 80 89 2 89 91 5 91 53 8 53 34 8 34 74 9 74 68 3 68 52 9 52 49 1 49 37 6 37 9 1 9 4 6 4 23 7 23...
output:
8
result:
ok single line: '8'
Test #4:
score: 10
Accepted
time: 19ms
memory: 12988kb
input:
1000 181296 999999 8 650 743998 650 320 834464 320 664 488124 664 411 814784 411 887 825242 887 322 881390 322 854 695099 854 719 343142 719 425 765369 425 585 594854 585 874 874574 874 843 544404 843 87 599144 87 128 930905 128 914 206730 914 461 159790 461 963 719162 963 751 717754 751 287 335806 ...
output:
2
result:
ok single line: '2'
Test #5:
score: 10
Accepted
time: 14ms
memory: 11544kb
input:
1000 90509 777 832 913 1.94107 913 650 1.69906 650 202 1.33482 202 60 1.4781 60 238 1.52459 238 177 1.50846 177 309 1.54601 309 316 1.77919 316 335 1.75991 335 748 1.1945 748 598 1.66309 598 513 1.87494 513 427 1.83812 427 728 1.06084 728 540 1.85968 540 553 1.18499 553 288 1.35035 288 291 1.32966 2...
output:
225
result:
ok single line: '225'
Test #6:
score: 10
Accepted
time: 7ms
memory: 10960kb
input:
2222 16156 98765 69 963 6.98159 963 1999 5.60671 1999 108 8.545 108 1258 4.08367 1258 1709 4.66681 1709 90 7.35292 90 1300 5.95097 1300 1623 8.72925 1623 139 4.89662 139 423 8.28057 423 1235 6.44084 1235 13 6.82704 13 670 5.74766 670 365 8.28991 365 324 8.73557 324 2195 6.35717 2195 1747 6.16023 174...
output:
2014
result:
ok single line: '2014'
Test #7:
score: 10
Accepted
time: 3ms
memory: 6964kb
input:
3333 44115 99999 653 2442 46.4009 2442 297 73.3315 297 1959 94.7193 1959 2923 20.1875 2923 1831 80.6127 1831 1677 64.5939 1677 1809 38.0042 1809 3193 49.9268 3193 708 22.7042 708 2580 73.3195 2580 3154 18.7393 3154 1163 61.1456 1163 762 13.5259 762 420 50.3727 420 633 79.6002 633 247 99.5519 247 266...
output:
441
result:
ok single line: '441'
Test #8:
score: 10
Accepted
time: 107ms
memory: 38908kb
input:
5000 25014 999999 338 3873 1.20593 3873 3400 1.67902 3400 3658 1.17251 3658 3594 1.89888 3594 4753 1.59833 4753 1502 1.6123 1502 2304 1.496 2304 483 1.54973 483 4001 1.16819 4001 29 1.03435 29 3351 1.44136 3351 1970 1.60173 1970 1611 1.3438 1611 614 1.48917 614 1372 1.86184 1372 4755 1.54248 4755 22...
output:
57948
result:
ok single line: '57948'
Test #9:
score: 10
Accepted
time: 89ms
memory: 43716kb
input:
5000 28666 999983 11 1640 1.45937 1640 2345 2.32915 2345 2021 1.94338 2021 3616 1.14568 3616 763 2.09215 763 3527 2.10157 3527 1128 1.61896 1128 3439 1.22679 3439 269 2.30751 269 1988 2.07579 1988 1503 2.60381 1503 1122 1.99496 1122 1808 2.76742 1808 2921 2.97836 2921 4963 1.1324 4963 2887 2.45812 2...
output:
46312
result:
ok single line: '46312'
Test #10:
score: 10
Accepted
time: 76ms
memory: 23884kb
input:
5000 24915 1000000 4631 707 1.85882 707 480 2.82335 480 1411 3.0055 1411 1845 3.18194 1845 3884 3.67791 3884 4882 1.43678 4882 679 3.41302 679 3407 3.36917 3407 259 1.66206 259 1652 2.74687 1652 958 3.22253 958 1052 3.26796 1052 2706 2.51034 2706 4773 2.83871 4773 253 3.74137 253 4109 1.04059 4109 2...
output:
36693
result:
ok single line: '36693'