QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#759707#7048. Delivery RoutewelikestudyingRE 38ms10668kbC++231.4kb2024-11-18 11:24:382024-11-18 11:24:40

Judging History

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

  • [2024-11-18 11:24:40]
  • 评测
  • 测评结果:RE
  • 用时:38ms
  • 内存:10668kb
  • [2024-11-18 11:24:38]
  • 提交

answer

#include<bits/stdc++.h>
#define up(a,b,c)for(int a=b;a<=c;++a)
const int N=11e5,inf=1e9;
using namespace std;
int n,x,y,s,fa[N],ds[N],cc[N];
struct edge
{
	int v,w;
	bool operator < (edge b)const
	{
		return b.w<w;
	}
};
vector<edge>to[N],at[N];
vector<int>ccf[N];
priority_queue<edge>bbc;
void dfs(int u)
{
	if(!fa[u])
	{
		fa[u]=x,ccf[x].push_back(u);
		for(edge z:to[u])dfs(z.v);
	}
}
void dj(int s)
{
	s=fa[s];
	for(int u:ccf[s])
		if(ds[u]<inf)bbc.push({u,ds[u]});
	while(!bbc.empty())
	{
		int u=bbc.top().v;bbc.pop();
		for(edge z:to[u])
			if(ds[z.v]>ds[u]+z.w)
				bbc.push({z.v,ds[z.v]=ds[u]+z.w});
		for(edge z:at[u])
			ds[z.v]=min(ds[u]+z.w,ds[z.v]);
		while(!bbc.empty()&&ds[bbc.top().v]<bbc.top().w)bbc.pop();
	}
	for(int u:ccf[s])
		for(edge z:at[u])
		{
			--cc[fa[z.v]];
			if(!cc[fa[z.v]])dj(z.v); 
		}
			
}
int main()
{
	cin>>n>>x>>y>>s;
	fill(ds,ds+n+1,inf),ds[s]=0;
	while(x--)
	{
		int u,v,w;cin>>u>>v>>w;
		to[u].push_back({v,w}),
		to[v].push_back({u,w});
	}
	up(i,1,n)if(!fa[i])x=i,dfs(i);
	while(y--)
	{
		int u,v,w;cin>>u>>v>>w;
		at[u].push_back({v,w}),++cc[fa[v]];
	}
	up(i,1,n)if(fa[i]==i&&!cc[i])dj(i);
	up(i,1,n)
		if(ds[i]<inf)
		{
			for(edge z:to[i])
				assert(ds[z.v]<=ds[i]+z.w);
			for(edge z:at[i])
				assert(ds[z.v]<=ds[i]+z.w);
		}
	up(i,1,n)
		if(ds[i]<inf)cout<<ds[i]<<'\n';
		else cout<<"NO PATH\n";
	return 0;
} 

詳細信息

Test #1:

score: 100
Accepted
time: 4ms
memory: 7756kb

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: 4ms
memory: 7724kb

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: 4ms
memory: 7696kb

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: 5ms
memory: 7780kb

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: 35ms
memory: 9224kb

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: 24ms
memory: 8636kb

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: 0ms
memory: 7632kb

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: 38ms
memory: 10668kb

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: -100
Runtime Error

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:


result: