QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#279710 | #7048. Delivery Route | bachbeo2007 | AC ✓ | 32ms | 12364kb | C++23 | 3.0kb | 2023-12-08 23:29:03 | 2023-12-08 23:29:03 |
Judging History
answer
// Judges with GCC >= 12 only needs Ofast
// #pragma GCC optimize("O3,no-stack-protector,fast-math,unroll-loops,tree-vectorize")
// MLE optimization
// #pragma GCC optimize("conserve-stack")
// Old judges
// #pragma GCC target("sse4.2,popcnt,lzcnt,abm,mmx,fma,bmi,bmi2")
// New judges. Test with assert(__builtin_cpu_supports("avx2"));
// #pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma,tune=native")
// Atcoder
// #pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma")
#include<bits/stdc++.h>
using namespace std;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
uniform_real_distribution<> pp(0.0,1.0);
#define int long long
#define ld long double
#define pii pair<int,int>
#define piii pair<int,pii>
#define fi first
#define se second
const int inf=1e18;
const int mod=998244353;
const int mod2=1e9+7;
const int maxn=25005;
const int maxq=500005;
const int maxl=20;
const int maxa=1000005;
int power(int a,int n){
int res=1;
while(n){
if(n&1) res=res*a%mod;
a=a*a%mod;n>>=1;
}
return res;
}
int n,x,y,s,dist[maxn],cc[maxn],cnt;
bool vis[maxn];
vector<int> topo,child[maxn],adj2[maxn];
vector<pii> edge[maxn],adj[maxn],e;
void dfs(int u){
cc[u]=cnt;child[cnt].push_back(u);
for(pii v:edge[u]){
if(cc[v.first]) continue;
dfs(v.first);
}
}
void dfs2(int u){
vis[u]=true;
for(int v:adj2[u]){
if(!vis[v]) dfs2(v);
}
topo.push_back(u);
}
void solve(){
cin >> n >> x >> y >> s;
for(int i=1;i<=x+y;i++){
int u,v,w;cin >> u >> v >> w;
if(i<=x){
edge[u].push_back({v,w});
edge[v].push_back({u,w});
}
else{
e.push_back({u,v});
adj[u].push_back({v,w});
}
}
for(int i=1;i<=n;i++){
dist[i]=inf;
if(!cc[i]){cnt++;dfs(i);}
}
for(pii x:e) adj2[cc[x.fi]].push_back(cc[x.se]);
for(int i=1;i<=cnt;i++){
if(!vis[i]) dfs2(i);
}
reverse(topo.begin(),topo.end());
dist[s]=0;
for(int cs:topo){
priority_queue<pii,vector<pii>,greater<pii>> pq;
for(int v:child[cs]){
if(dist[v]!=inf) pq.push({dist[v],v});
}
while(!pq.empty()){
int u=pq.top().se,d=pq.top().fi;pq.pop();
if(dist[u]!=d) continue;
for(pii v:edge[u]){
if(dist[v.first]>d+v.second){
dist[v.first]=d+v.second;
pq.push({d+v.second,v.first});
}
}
}
for(int u:child[cs]){
if(dist[u]==inf) continue;
for(pii v:adj[u]) dist[v.first]=min(dist[v.first],dist[u]+v.second);
}
}
for(int i=1;i<=n;i++){
if(dist[i]==inf) cout << "NO PATH\n";
else cout << dist[i] << '\n';
}
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);
int test=1;//cin >> test;
while(test--) solve();
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 6216kb
input:
6 3 3 4 1 2 5 3 4 5 5 6 10 3 5 -100 4 6 -100 1 3 -10
output:
NO PATH NO PATH 5 0 -95 -100
result:
ok 6 lines
Test #2:
score: 0
Accepted
time: 1ms
memory: 6372kb
input:
100 500 500 4 13 20 329 41 10 63 100 90 297 15 79 163 24 67 747 29 68 443 73 98 565 10 41 921 79 62 973 31 85 270 25 29 672 34 43 391 30 92 604 58 82 90 28 16 460 53 63 350 91 98 260 70 22 232 5 36 335 37 32 339 4 48 940 85 1 233 95 78 323 62 79 688 49 57 576 10 54 103 33 78 541 88 22 171 4 48 408 2...
output:
-3619 -3536 NO PATH 0 NO PATH -7205 -6588 -2243 -2898 -691 -6755 -710 -4236 -3929 -941 -4827 -4796 NO PATH -6827 -4246 -4759 -1991 -5025 -1522 -6643 -6453 -3084 -4740 -6448 -5552 -3800 -2700 -7006 -3915 -433 NO PATH -2767 NO PATH 158 -2524 -628 -7166 -3859 -2838 -2168 -7106 -2726 112 -3844 544 -3860...
result:
ok 100 lines
Test #3:
score: 0
Accepted
time: 0ms
memory: 6032kb
input:
50 100 50 24 26 39 94 44 42 47 15 39 28 10 25 37 28 12 3 36 22 34 9 36 74 28 12 35 25 22 63 48 7 86 29 37 69 9 10 4 36 9 31 28 34 54 6 1 89 33 25 17 36 10 47 5 35 9 7 14 65 44 50 96 31 1 35 37 29 4 28 34 27 35 18 74 34 8 37 13 17 2 19 48 47 20 43 98 26 16 91 13 29 63 20 43 48 5 35 54 39 15 69 10 33 ...
output:
NO PATH -3 NO PATH NO PATH -126 NO PATH -2 -98 -66 -62 -38 -144 51 15 NO PATH NO PATH 49 -43 -5 NO PATH 67 -79 NO PATH 0 -64 NO PATH -57 -141 114 -73 NO PATH 27 -81 -114 -117 -45 118 NO PATH NO PATH -85 NO PATH -94 NO PATH -47 -35 NO PATH -91 -15 -57 -52
result:
ok 50 lines
Test #4:
score: 0
Accepted
time: 2ms
memory: 6148kb
input:
300 2000 1000 208 251 61 2246 22 3 3153 81 124 1726 77 280 4372 14 169 592 186 46 4946 146 128 4639 148 296 2647 283 120 4786 197 139 435 59 89 4916 231 38 506 182 56 623 283 225 3941 298 117 3457 141 24 1734 18 10 1102 86 45 813 261 271 2541 19 263 3219 250 260 3725 131 298 110 285 237 331 292 184 ...
output:
-41459 -14899 -27143 -9932 -10727 -18844 -27091 -10217 -7973 1635 -5432 -29336 -10123 -10958 -6204 -18534 -38070 1002 -2183 1288 -27814 -27410 -38724 -33495 -39524 -26651 -7308 -13916 -29867 -37448 -13090 -28028 -10532 -7565 7438 -18717 -37908 -34214 -1458 -7125 -43190 -7876 -39417 -10082 -25107 -63...
result:
ok 300 lines
Test #5:
score: 0
Accepted
time: 11ms
memory: 8752kb
input:
5000 30000 30000 617 2616 3637 3037 1979 3188 582 3728 2476 2258 27 928 3410 4874 2914 1786 2307 916 4445 2888 299 1338 4271 9 328 3334 3112 2859 622 3874 2702 2754 1859 9598 2143 4393 2760 3714 4390 9070 205 1820 9332 2148 2583 2933 3483 4113 8894 1181 4261 7130 4053 1552 4229 4895 3533 2174 4893 1...
output:
-67443 -313642 -198812 NO PATH -216061 NO PATH -354020 -167160 NO PATH NO PATH NO PATH -123407 -136971 -153815 -163001 -310206 -266785 NO PATH -11515 NO PATH NO PATH NO PATH NO PATH -313978 -137141 -177928 NO PATH -117014 -255677 -301218 -50350 -24831 -234306 NO PATH -116670 -159417 NO PATH -94986 -...
result:
ok 5000 lines
Test #6:
score: 0
Accepted
time: 6ms
memory: 7888kb
input:
2500 25000 15000 1749 1794 1219 7486 2500 487 9275 288 417 4197 588 2409 3850 2037 2028 414 2045 1288 9326 1926 2297 1441 1226 1936 1740 2410 2164 6243 27 1765 2837 217 1152 8208 1856 1256 3484 2443 1506 7334 1979 397 8827 376 678 8152 2301 2161 672 830 1576 6517 1248 2065 4590 1708 362 1039 231 649...
output:
-239558 -295742 -151871 -235692 -118055 -91058 -176020 -122338 NO PATH -152392 -159368 -206987 -52416 -18945 -248020 NO PATH -308703 -163929 -269618 -280507 NO PATH -332401 -256172 -59263 -5461 -39362 -64505 -194785 -57959 -203148 -159121 -265319 -27698 NO PATH -123225 -218853 -92677 -256479 NO PATH...
result:
ok 2500 lines
Test #7:
score: 0
Accepted
time: 1ms
memory: 6368kb
input:
20 30 10 10 3 20 4 20 3 6 8 1 0 2 4 10 16 8 7 6 16 2 19 11 6 20 3 1 18 16 10 8 12 5 10 12 1 4 7 7 1 16 10 14 3 6 1 8 5 10 8 1 9 4 2 18 1 8 10 18 8 11 19 9 14 15 5 14 20 4 7 9 10 10 16 3 13 3 0 10 12 7 11 19 10 12 10 5 3 20 3 20 13 10 9 19 2 12 15 -7 14 9 -1 16 5 -4 3 5 5 16 4 -7 16 15 -8 8 3 -2 17 6...
output:
1 6 -1 -4 -1 5 3 1 -2 0 6 1 -1 -1 -6 3 NO PATH 8 0 0
result:
ok 20 lines
Test #8:
score: 0
Accepted
time: 20ms
memory: 10252kb
input:
25000 1 50000 24312 24312 24433 8144 17265 22370 -4283 10464 19237 2138 11021 7812 5792 4199 954 5726 16276 5915 7598 6844 15815 3315 18963 4081 -1786 5533 13800 -4801 8530 2328 7922 16812 4440 -7840 3784 13623 1986 15402 17569 699 14562 22034 3476 22451 14926 6985 8086 22571 -9299 18380 1806 -2447 ...
output:
-52735500 -69001383 -1973939 -10077099 -68577102 -90397581 -84863206 -86384458 -11625648 -97072526 -84221928 -37245201 -44521403 -90550387 -55349368 -2655653 -79740492 -31558186 -9250655 -1370465 -85296570 -21376102 -66393066 -96538611 -23294298 -98375432 -11763617 -83363963 -46101652 -92529073 -948...
result:
ok 25000 lines
Test #9:
score: 0
Accepted
time: 32ms
memory: 11328kb
input:
15000 50000 50000 2980 8138 14295 156 14091 5803 1104 9541 3948 1347 4992 276 8716 4555 12611 2214 5311 10189 41 10954 3739 462 12690 5600 3008 844 12753 8610 2215 7000 5779 13666 10422 4 13562 7514 2180 13808 14312 497 14371 5979 2804 2997 12955 487 14892 13071 236 868 2287 8496 13817 14143 5549 29...
output:
NO PATH -139175 -15027 -137552 -206194 -136633 8534 -37239 -139253 -137710 -251106 -43191 -231613 -260062 -165076 -135479 -99738 -124248 -140428 -274731 -140842 -63291 -78143 -72274 -11557 -131524 -41420 -137289 -138234 -138583 -222663 -274085 -205252 9308 -140242 -219365 -39153 -135547 -92471 -1394...
result:
ok 15000 lines
Test #10:
score: 0
Accepted
time: 18ms
memory: 9096kb
input:
25000 50000 100 24926 344 21185 844 1733 2948 6946 19614 24908 865 1504 5800 35 4353 11899 656 22205 16892 128 13526 7020 145 19428 21597 5260 18612 1771 664 5433 18297 270 2937 14651 134 15557 17564 6480 13610 2484 41 11018 24937 782 20731 20236 324 23471 19722 8297 23255 2303 9292 23029 21187 494 ...
output:
117436 236215 170464 130284 121004 120580 NO PATH 156516 NO PATH 172924 127002 NO PATH 46862 NO PATH 483674 NO PATH 80136 573261 250202 NO PATH 114680 NO PATH NO PATH 267941 95114 NO PATH 81257 NO PATH 259830 258834 217636 206422 NO PATH 207120 212521 546941 326324 NO PATH NO PATH 96105 322347 18019...
result:
ok 25000 lines
Test #11:
score: 0
Accepted
time: 17ms
memory: 12364kb
input:
25000 50000 30000 1 20522 24575 7979 24445 23772 2685 23447 20629 1735 22202 22775 4427 23982 24784 3812 22156 21932 6869 20728 23537 5149 20739 21918 6313 24679 23506 4111 21568 21868 3920 22940 21263 8787 21449 21991 2928 23355 22068 8970 23580 21757 3433 24934 24328 7547 24355 21221 1813 20922 21...
output:
0 0 -4 -4 -12 -12 -28 -28 -60 -60 -124 -124 -252 -252 -508 -508 -1020 -1020 -2044 -2044 -4092 -4092 -8188 -8188 -16380 -16380 -16382 -16382 -16386 -16386 -16394 -16394 -16410 -16410 -16442 -16442 -16506 -16506 -16634 -16634 -16890 -16890 -17402 -17402 -18426 -18426 -20474 -20474 -24570 -24570 -32762...
result:
ok 25000 lines