QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#698817#7048. Delivery RouteWedonotLikeStudyingAC ✓13ms11316kbC++232.9kb2024-11-01 22:12:462024-11-01 22:12:47

Judging History

你现在查看的是最新测评结果

  • [2024-11-01 22:12:47]
  • 评测
  • 测评结果:AC
  • 用时:13ms
  • 内存:11316kb
  • [2024-11-01 22:12:46]
  • 提交

answer

#include <bits/stdc++.h>
#define rep(a,b,c) for(int a=(b);a<=(c);a++)
#define per(a,b,c) for(int a=(b);a>=(c);a--)
#define ll long long
#define vi vector<int>
#define pb emplace_back
#define mem(a,b) memset(a,b,sizeof(a))
#define pii pair<int,int>
#define mp make_pair
#define fi first
#define se second
using namespace std;

template<class T>inline void read(T &x) {
	T f=1; x=0; char s=getchar();
	while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();}
	while(s>='0'&&s<='9'){x=x*10+s-'0';s=getchar();}
	x*=f;
}

const int M=2e5;
const int N=5e4;
const ll inf=1e18;

struct Edge {
	int u,v;
	ll w;
}e[M+5];
int head[N+5],ecnt,Head[N+5],Ecnt;
inline void adde(int u,int v,int w) { e[++ecnt].v=v;e[ecnt].w=w;e[ecnt].u=head[u];head[u]=ecnt; }
inline void add(int u,int v,int w) { adde(u,v,w); adde(v,u,w); }
inline void adde(int u,int v,ll w) { e[++ecnt].v=v;e[ecnt].w=w;e[ecnt].u=head[u];head[u]=ecnt; }
inline void add(int u,int v,ll w) { adde(u,v,w); adde(v,u,w); }

int fa[N+5];
inline int find(int x) { return (fa[x]==x)?(x):(fa[x]=find(fa[x])); }

int du[N+5],n,x,y,s,a[N+5],b[N+5],c[N+5],st;
ll dis[N+5];

vi lt[N+5];

queue<int> q;
int vs[N+5];
vector<pii> ed[N+5];
inline void bfs() {
	q.push(s);
	vs[s]=1;
	while(!q.empty()) {
		int u=q.front(); q.pop();
		for(int i=head[u],v;i;i=e[i].u) {
			v=e[i].v;
			if(vs[v]) continue;
			vs[v]=1;
			q.push(v);
		}
	}
}

struct Node {
    int u;
	ll d;
    bool operator <(const Node& rhs) const {
        return d>rhs.d;
    }
};

priority_queue <Node> Q;
inline void dij(int S) {
	for(int X:lt[S]) Q.push((Node){X,dis[X]});
    while(!Q.empty()) {
        Node fr=Q.top(); Q.pop();
        int u=fr.u;
		ll d=fr.d;
        if(d!=dis[u]) continue;
        for (int i=head[u];i;i=e[i].u) {
            int v=e[i].v;
			ll w=e[i].w;
            if (dis[u]+w<dis[v]) {
                dis[v]=dis[u]+w;
                Q.push((Node){v,dis[v]});
            }
        }
    }
}

inline void solve() {
	read(n); read(x); read(y); read(s);
	rep(i,1,n) fa[i]=i,dis[i]=inf;
	st=n+1;
	rep(i,1,x) {
		int u,v,w;
		read(u); read(v); read(w);
		add(u,v,w);
		u=find(u); v=find(v);
		fa[u]=v;
	}
	rep(i,1,n) lt[find(i)].pb(i);
	rep(i,1,y) read(a[i]),read(b[i]),read(c[i]);
	dis[s]=0;
	Ecnt=ecnt;
	rep(i,1,n) Head[i]=head[i];
	rep(i,1,y) adde(a[i],b[i],c[i]);
	bfs();
	rep(i,1,n) head[i]=Head[i]; ecnt=Ecnt;
	rep(i,1,y) {
		int X=find(a[i]),Y=find(b[i]);
		if((!vs[X])||(!vs[Y])) continue;
		ed[X].pb(mp(Y,i));
		du[Y]++;
	}
	rep(i,1,n) if(find(i)==i) {
		if(!vs[i]) continue;
		if(!du[i]) q.push(i);
	}
	dis[s]=0;
	while(!q.empty()) {
		int u=q.front(); q.pop();
		dij(u);
		for(pii v:ed[u]) {
			du[v.fi]--;
			int ei=v.se;
			dis[b[ei]]=min(dis[b[ei]],dis[a[ei]]+c[ei]);
			if(!du[v.fi]) q.push(v.fi);
		}
	}
	rep(i,1,n)
	if(dis[i]==inf) puts("NO PATH");
	else printf("%lld\n",dis[i]);
}

int main() {
	//int T; read(T); while(T--)
	solve();
}

这程序好像有点Bug,我给组数据试试?

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 7960kb

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: 8168kb

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: 1ms
memory: 5836kb

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: 1ms
memory: 7884kb

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: 8ms
memory: 10268kb

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: 7156kb

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: 7868kb

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: 8ms
memory: 9752kb

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: 13ms
memory: 11316kb

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: 12ms
memory: 7948kb

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: 10ms
memory: 10988kb

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