QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#709063#4898. 基础图论练习题PorNPtree10 24ms28424kbC++231.1kb2024-11-04 11:07:072024-11-04 11:07:07

Judging History

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

  • [2024-11-04 11:07:07]
  • 评测
  • 测评结果:10
  • 用时:24ms
  • 内存:28424kb
  • [2024-11-04 11:07:07]
  • 提交

answer

#include<bits/stdc++.h>
#define LL long long
#define fr(x) freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);
using namespace std;
const int N=2e5+5,mod=998244353;
LL n,d[N],X[N];int A,B,fa[N];
struct node{int u,v;LL w;}e[N];
vector<node>g;
inline int getf(int x){return x==fa[x]?x:fa[x]=getf(fa[x]);}
inline LL KR()
{
	iota(fa,fa+n,0);
	sort(g.begin(),g.end(),[](node X,node Y){return X.w<Y.w;});
	int ans=0;
	for(auto [u,v,w]:g)
	{
		u=getf(u),v=getf(v);
		if(u^v) fa[v]=u,ans=(ans+w)%mod;
	}return ans;
}
namespace sol1
{
	inline void sol()
	{
		for(int i=1;i<=B;i++) g.push_back(e[i]);
		for(int i=1;i<=A;i++) for(int j=0;j+d[i]<n;j++) g.push_back({j,j+d[i],X[i]});
		cout<<KR();
	}
}
int main()
{
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);cin>>n>>A>>B;
	for(int i=1;i<=A;i++) cin>>d[i]>>X[i];
	for(int i=1,u,v,w;i<=B;i++) cin>>u>>v>>w,e[i]={u,v,w};
	if(n<=200000&&A<=10) return sol1::sol(),0;
	if(A==2&&!B)
	{
		int ans;LL cnt;
		if(X[1]>X[2]) swap(X[1],X[2]),swap(d[1],d[2]);
		ans=(n-d[1])%mod*X[1]%mod;
		cnt=max(d[1]+d[2]-n,__gcd(d[1],d[2]));
		ans=(ans+(d[1]-cnt)%mod*X[2])%mod;cout<<ans;
	}
	return 0;
}

详细

Subtask #1:

score: 4
Accepted

Test #1:

score: 4
Accepted
time: 15ms
memory: 19212kb

input:

161199 9 46510
147335 540442844
159493 801351455
149342 821625305
128476 843250712
95524 275754315
139315 106523502
93575 680460786
155498 328812257
146020 410466645
79992 141967 50596784
152210 68644 268349216
72549 96959 42994091
93869 27394 945120577
2909 81886 270684270
12735 35026 871917997
974...

output:

359714743

result:

ok 1 number(s): "359714743"

Test #2:

score: 4
Accepted
time: 23ms
memory: 28424kb

input:

168549 9 49402
160577 34610415
114623 670751010
74448 676966248
53782 845469137
130729 375561046
31610 261496571
134601 154875802
136129 905308676
166248 499420220
69637 72676 875637640
160442 125460 1269794
146261 61770 714794725
137610 1291 490170432
162092 81850 488118013
106400 48193 276190368
4...

output:

520439176

result:

ok 1 number(s): "520439176"

Test #3:

score: 4
Accepted
time: 20ms
memory: 16144kb

input:

127164 9 45109
56483 490066497
70966 229077054
87305 993081887
72423 442762798
80262 200507011
101712 162752728
67532 590730535
44956 565466274
124237 429166816
13030 8906 742024040
97259 101468 187678659
13401 4301 143856524
125750 80473 258719294
106155 10339 592121345
120034 92354 50915550
112430...

output:

211463174

result:

ok 1 number(s): "211463174"

Test #4:

score: 4
Accepted
time: 24ms
memory: 18108kb

input:

158784 9 48415
138305 177767002
147417 50196642
85527 776201932
144377 990389932
118355 310906417
145220 218744495
145002 132736644
51947 834751363
139733 839880491
158443 157692 159261414
111518 14927 747973081
37498 66196 69874791
11597 115114 22394413
16704 133459 109302190
112143 46551 813021872...

output:

151875883

result:

ok 1 number(s): "151875883"

Test #5:

score: 4
Accepted
time: 12ms
memory: 6892kb

input:

111371 0 45933
13298 59545 852258097
94111 54245 459369673
40744 23311 644404848
37039 92443 220984611
17374 43165 421794343
57652 57965 470479953
62977 14481 563172671
102144 3471 36594913
46628 43278 11508424
55965 80136 777230453
56962 35374 349098036
34825 27995 339605509
43021 17657 780921827
5...

output:

92500087

result:

ok 1 number(s): "92500087"

Subtask #2:

score: 0
Wrong Answer

Dependency #1:

100%
Accepted

Test #6:

score: 0
Wrong Answer
time: 13ms
memory: 6784kb

input:

191116 49595 45279
87483 815631830
153579 433065789
167569 346797140
98560 154881536
170720 13622837
133236 561208103
155537 421316363
140536 514298139
6005 986290017
154400 85233907
166826 351094521
174419 304435906
173900 61174962
112778 693574534
104503 745038995
134920 31228457
117606 662581798
...

output:


result:

wrong answer Answer contains longer sequence [length = 1], but output contains 0 elements

Subtask #3:

score: 6
Accepted

Test #11:

score: 6
Accepted
time: 1ms
memory: 7744kb

input:

569435269457904707 2 0
490445920091092693 772271583
144842828305643603 609043885

output:

884694794

result:

ok 1 number(s): "884694794"

Test #12:

score: 6
Accepted
time: 1ms
memory: 7648kb

input:

946929772456816659 2 0
589193907831915013 196301185
485768367910597533 207014034

output:

790540706

result:

ok 1 number(s): "790540706"

Test #13:

score: 6
Accepted
time: 1ms
memory: 7724kb

input:

693038683299151358 2 0
654733556025919068 724998910
450253521190874799 187460097

output:

122292064

result:

ok 1 number(s): "122292064"

Test #14:

score: 6
Accepted
time: 1ms
memory: 7744kb

input:

572269482188906358 2 0
545978502848607475 331750201
488577730099900109 477584735

output:

429885702

result:

ok 1 number(s): "429885702"

Test #15:

score: 6
Accepted
time: 1ms
memory: 7652kb

input:

984888155303961325 2 0
421568681423492040 823358650
324408005979881943 905919848

output:

551223124

result:

ok 1 number(s): "551223124"

Test #16:

score: 6
Accepted
time: 1ms
memory: 5608kb

input:

968068649251960108 2 0
932666179822285222 303897491
422068063538287737 405622211

output:

516717723

result:

ok 1 number(s): "516717723"

Test #17:

score: 6
Accepted
time: 1ms
memory: 5600kb

input:

973235486287221374 2 0
604729607242747292 566399250
440704799734330948 93237801

output:

772791524

result:

ok 1 number(s): "772791524"

Test #18:

score: 6
Accepted
time: 1ms
memory: 5680kb

input:

980842002786834388 2 0
921076927921054095 989436809
917078581302025088 354268450

output:

387335763

result:

ok 1 number(s): "387335763"

Test #19:

score: 6
Accepted
time: 1ms
memory: 5744kb

input:

584600268153835325 2 0
436736455094118542 788823700
379215887395241676 440751386

output:

178749302

result:

ok 1 number(s): "178749302"

Test #20:

score: 6
Accepted
time: 1ms
memory: 7732kb

input:

984888155303961325 2 0
421568681423492040 823358650
324408005979881943 905919848

output:

551223124

result:

ok 1 number(s): "551223124"

Subtask #4:

score: 0
Wrong Answer

Dependency #3:

100%
Accepted

Test #21:

score: 0
Wrong Answer
time: 2ms
memory: 10384kb

input:

569435269457904707 2 48002
490445920091092693 772271583
144842828305643603 609043885
71626464779726163 20936760728342582 933619218
254533877531926689 561120543297327423 444805145
102181371350776436 64807827761321835 63236550
442490347461393187 274703226312639148 379888813
153103619447430279 56932615...

output:


result:

wrong answer Answer contains longer sequence [length = 1], but output contains 0 elements

Subtask #5:

score: 0
Wrong Answer

Test #31:

score: 0
Wrong Answer
time: 1ms
memory: 7660kb

input:

755526150476311190 942 0
492334667739348527 1
755523898623296976 1
532486636690994793 1
755526150476030559 1
755526150476249097 1
502164090270592200 1
657422656495814703 1
487200614853438190 1
311037325561173142 1
755526150475651155 1
125287404340238660 1
755524914808674090 1
755526150476177007 1
75...

output:


result:

wrong answer Answer contains longer sequence [length = 1], but output contains 0 elements

Subtask #6:

score: 0
Skipped

Dependency #3:

100%
Accepted

Dependency #5:

0%

Subtask #7:

score: 0
Skipped

Dependency #3:

100%
Accepted

Dependency #5:

0%

Subtask #8:

score: 0
Skipped

Dependency #5:

0%

Subtask #9:

score: 0
Skipped

Dependency #1:

100%
Accepted

Dependency #2:

0%