QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#709142 | #7048. Delivery Route | Loxilante | AC ✓ | 34ms | 24460kb | C++20 | 2.4kb | 2024-11-04 12:13:45 | 2024-11-04 12:13:47 |
Judging History
answer
/*
Auth: Loxilante
Date: 2023-08-24 20:35:20
Prog: bzoj2200.cpp
Think twice, code once. Think once, debug FOREVER!
*/
#define F_C
#include <bits/stdc++.h>
#define rep(i, l, r) for(int i = l; i < r; i++)
#define hrp(i, l, r) for(int i = l; i <= r; i++)
#define rev(i, r, l) for(int i = r; i >= l; i--)
#define ms(n, t) memset(n, t, sizeof(n))
#define pb push_back
#define int ll
#ifndef JOEON
#define D(...) 97
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
template<typename tn = int> inline tn next(void) { tn k; cin>>k; return k; }
const int U = 1e6;
int to[U], head[U], nxt[U], val[U], tot;
void add(int x, int y, int z)
{
val[++tot] = z; to[tot] = y; nxt[tot] = head[x]; head[x] = tot;
}
int bel[U], deg[U], cntb;
vector<int> block[U];
void dfs(int e)
{
bel[e] = cntb;
for(int i = head[e]; i; i = nxt[i])
{
int y = to[i];
if (!bel[y]) dfs(y);
}
}
int dis[U];
bool vis[U];
queue<int> que;
void dijkstra(int e)
{
priority_queue<pii, vector<pii>, greater<pii> > pq;
for(int i : block[e]) pq.push({dis[i], i});
int sb = 0;
while(pq.size())
{
int x = pq.top().second; pq.pop();
if (vis[x]) continue;
vis[x] = 1;
for(int i = head[x]; i; i = nxt[i])
{
int y = to[i], z = val[i];
if (dis[y] > dis[x]+z)
{
dis[y] = dis[x]+z;
if (bel[y] == e) pq.push({dis[y], y});
}
if (bel[y] != e && !(--deg[bel[y]])) que.push(bel[y]);
}
}
}
void toposort(int s)
{
ms(dis, 0x3f);
dis[s] = 0;
hrp(i, 1, cntb) if (!deg[i]) que.push(i);
while(que.size())
{
int t = que.front(); que.pop();
dijkstra(t);
}
}
signed main(void)
{
#ifdef JOEON
freopen("C:\\Users\\32676\\Desktop\\IN.txt", "r", stdin);
freopen("C:\\Users\\32676\\Desktop\\OUT.txt", "w", stdout);
#endif
ios::sync_with_stdio(false);
cin.tie(0);
int n, m1, m2, s;
cin>>n>>m1>>m2>>s;
rep(i, 0, m1)
{
int a, b, c;
cin>>a>>b>>c;
add(a, b, c);
add(b, a, c);
}
hrp(i, 1, n) if (!bel[i]) cntb++, dfs(i);
hrp(i, 1, n) block[bel[i]].pb(i);
rep(i, 0, m2)
{
int a, b, c;
cin>>a>>b>>c;
add(a, b, c);
}
hrp(i, 1, n)
{
for(int j = head[i]; j; j = nxt[j])
{
int y = to[j];
if (bel[i] != bel[y]) deg[bel[y]]++;
}
}
toposort(s);
hrp(i, 1, n)
{
if (dis[i] >= 1e13) cout<<"NO PATH"<<endl;
else cout<<dis[i]<<endl;
}
return 0;
}
/*
*/
这程序好像有点Bug,我给组数据试试?
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 17456kb
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: 0ms
memory: 20456kb
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: 17732kb
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: 17836kb
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: 7ms
memory: 21236kb
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: 9ms
memory: 20664kb
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: 4ms
memory: 17520kb
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: 18ms
memory: 21564kb
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: 34ms
memory: 23272kb
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: 22ms
memory: 21016kb
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: 19ms
memory: 24460kb
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