QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#18753#2332. JuicyQingyuAC ✓26ms3756kbC++202.1kb2022-01-26 13:02:482022-05-06 02:23:17

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-05-06 02:23:17]
  • 评测
  • 测评结果:AC
  • 用时:26ms
  • 内存:3756kb
  • [2022-01-26 13:02:48]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int MAXN = 112;
int parent[MAXN],Rank[MAXN]; //we can’t use rank as a variable in C++
void Init(){
   for(int i=1;i<MAXN;i++){
      parent[i]=i;
      Rank[i]=1;
   }
}
int Find(int x){ // Path Compression
   return x==parent[x] ? x : parent[x] = Find(parent[x]);
}
void Union(int x,int y){ //Union by Rank
   int rootx = Find(x),rooty = Find(y);
   if(rootx!=rooty){
      if(Rank[rootx] < Rank[rooty])    swap(rootx,rooty);
      parent[rooty]=rootx;
      if(Rank[rootx] == Rank[rooty])    Rank[rootx]++;
   }
}
long double L = 1,ans;
int a,b,m;
int p,q,ansp,ansq;
bool choose[11];
struct EDGE{
   long long int happiness,energy,from,to;
   bool operator<(const EDGE& rhs)const{
      return happiness-L*energy>rhs.happiness-L*rhs.energy;
   }
}edge[1000];

int main(){
   ios_base::sync_with_stdio(0);
   cin.tie(0);
   cin>>a>>b>>m;
   for(int i=0;i<m;i++){
      cin>>edge[i].from>>edge[i].to>>edge[i].happiness>>edge[i].energy;
      if(edge[i].from<1||edge[i].from>a+b+1||edge[i].to<1||edge[i].from>a+b+1||edge[i].happiness<0||edge[i].happiness>1000000||edge[i].energy<1||edge[i].energy>1000000)
         return -1;
   }
   int limit=1<<a;
   do{
      ans=L;
      sort(edge,edge+m);
      L=-1;
      for(int i=0;i<limit;i++){
         int x=i,cnt=b;
         for(int j=1;j<=a;j++){
            if(x%2){
               choose[j]=true;
               cnt++;
            }
            else
               choose[j]=false;
            x>>=1;
         }
         p=0;q=0;
         Init();
         for(int j=0;j<m;j++){
            if(Find(edge[j].from)!=Find(edge[j].to)&&(edge[j].from>a||choose[edge[j].from])&&(edge[j].to>a||choose[edge[j].to])){
               Union(edge[j].from,edge[j].to);
               cnt--;
               p+=edge[j].happiness;
               q+=edge[j].energy;
            }
         }
         if(cnt==0&&(long double)p/q>L){
            L=(long double)p/q;
            ansp=p;
            ansq=q;
         }

      }
   }while(ans>=1e-12&&abs(ans-L)/ans>1e-7);
   cout<<(long long int)ansp/__gcd(ansp,ansq)*ansq/__gcd(ansp,ansq)<<endl;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3680kb

input:

1 3
4
1 2 10 1
2 3 10 1
3 4 10 1
1 5 10 1

output:

10

result:

ok single line: '10'

Test #2:

score: 0
Accepted
time: 2ms
memory: 3600kb

input:

1 3
5
1 2 100000 1
2 3 0 20
3 4 1 1
4 5 1 1
2 5 1 400

output:

2300046

result:

ok single line: '2300046'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3656kb

input:

0 9
1000
1 8 626306 557772
1 5 118467 557772
1 6 312736 557772
1 5 450048 557772
1 6 671869 557772
1 2 201952 557772
1 7 482291 557772
1 6 568714 557772
1 7 507334 557772
1 3 827381 557772
1 9 64476 557772
1 3 97921 557772
1 10 171372 557772
1 6 398011 557772
1 5 180738 557772
1 9 389126 557772
1 8 ...

output:

11225730706326

result:

ok single line: '11225730706326'

Test #4:

score: 0
Accepted
time: 2ms
memory: 3600kb

input:

3 10
20
1 12 0 9800
3 8 0 588220
3 7 0 884401
4 10 0 478567
5 10 0 468273
5 6 0 343416
6 14 0 773171
6 9 0 202457
6 8 0 915313
6 14 0 866660
7 14 0 602479
7 13 0 543301
7 12 0 476987
7 12 0 976896
8 10 0 58965
9 12 0 840511
11 12 0 328452
11 9 0 807606
12 11 0 230845
13 4 0 540292

output:

0

result:

ok single line: '0'

Test #5:

score: 0
Accepted
time: 4ms
memory: 3548kb

input:

3 10
20
1 14 0 158481
2 11 0 864783
2 6 0 189003
3 8 0 998684
4 13 0 158856
5 10 0 231886
5 8 0 711647
5 12 0 540385
6 10 0 496392
6 12 0 278936
7 8 0 392783
7 12 0 657545
7 12 0 974547
7 6 0 878578
8 11 0 145814
8 14 0 379450
9 14 0 301506
10 13 0 245344
10 4 0 189178
11 12 0 603023

output:

0

result:

ok single line: '0'

Test #6:

score: 0
Accepted
time: 3ms
memory: 3756kb

input:

2 10
100
1 13 23 277042
1 3 23 778805
1 8 23 508963
1 11 23 871712
1 9 23 108169
1 13 23 820891
1 6 23 345545
1 2 23 2442
1 3 23 517282
2 12 23 398231
2 8 23 831304
2 11 23 49458
2 13 23 758865
2 11 23 586788
2 10 23 357729
2 5 23 24589
2 12 23 86873
3 10 23 853448
3 9 23 734531
3 10 23 531852
3 8 2...

output:

71684

result:

ok single line: '71684'

Test #7:

score: 0
Accepted
time: 1ms
memory: 3628kb

input:

3 10
100
1 6 543252 893041
1 8 543252 49261
1 14 543252 751711
1 8 543252 511676
1 9 543252 435174
2 12 543252 517518
2 4 543252 606181
2 11 543252 708488
2 10 543252 771789
2 5 543252 351470
2 11 543252 204935
2 12 543252 366066
2 10 543252 710937
2 3 543252 48674
3 11 543252 616026
3 10 543252 415...

output:

2802338812

result:

ok single line: '2802338812'

Test #8:

score: 0
Accepted
time: 1ms
memory: 3692kb

input:

10 10
12
1 4 637151 1
11 20 227400 1
12 18 109668 1
13 18 319915 1
13 15 197754 1
14 20 383279 1
14 18 254786 1
14 16 794757 1
14 2 676662 1
17 19 858630 1
19 21 404303 1
19 20 337280 1

output:

50208774

result:

ok single line: '50208774'

Test #9:

score: 0
Accepted
time: 2ms
memory: 3484kb

input:

10 10
12
11 19 119068 1
12 21 94820 1
12 14 749543 1
13 21 570176 1
13 20 622578 1
13 5 922733 1
15 18 427570 1
16 17 642828 1
17 21 386293 1
18 21 710109 1
19 21 46394 1
20 21 406114 1

output:

58213232

result:

ok single line: '58213232'

Test #10:

score: 0
Accepted
time: 1ms
memory: 3600kb

input:

10 10
12
7 10 670258 1
11 13 643166 1
12 19 998616 1
12 14 979402 1
13 18 707580 1
15 16 668394 1
16 21 867668 1
17 21 56443 1
17 21 970413 1
18 20 251261 1
19 20 864989 1
20 21 643613 1

output:

18987755

result:

ok single line: '18987755'

Test #11:

score: 0
Accepted
time: 3ms
memory: 3480kb

input:

10 10
12
8 21 443179 1
11 21 529112 1
11 18 185041 1
12 13 461498 1
12 14 307593 1
12 16 543441 1
13 20 518883 1
14 21 354152 1
15 18 835315 1
17 21 258008 1
19 20 366544 1
21 11 568796 1

output:

53266950

result:

ok single line: '53266950'

Test #12:

score: 0
Accepted
time: 3ms
memory: 3596kb

input:

10 10
12
9 18 891728 1
11 15 111186 1
12 21 642768 1
13 20 542864 1
14 15 920082 1
15 16 778091 1
15 20 179089 1
15 18 219722 1
15 13 328994 1
17 21 595199 1
18 19 956284 1
18 21 813345 1

output:

74802893

result:

ok single line: '74802893'

Test #13:

score: 0
Accepted
time: 2ms
memory: 3552kb

input:

0 10
12
1 10 169793 1
1 11 456638 1
2 3 284478 1
2 7 6002 1
3 8 866374 1
4 8 439287 1
4 5 171099 1
4 10 10524 1
6 9 959587 1
7 8 517566 1
8 9 685869 1
9 10 356995 1

output:

12269215

result:

ok single line: '12269215'

Test #14:

score: 0
Accepted
time: 3ms
memory: 3488kb

input:

7 10
24
2 12 23432 555293
5 15 23432 955077
6 9 23432 847785
7 8 23432 490230
8 12 23432 601094
8 9 23432 712206
9 10 23432 127334
9 2 23432 869368
10 11 23432 67598
10 12 23432 397106
10 9 23432 72802
10 5 23432 520041
11 15 23432 832535
11 16 23432 398720
11 14 23432 977178
13 18 23432 902489
13 1...

output:

1364611750632

result:

ok single line: '1364611750632'

Test #15:

score: 0
Accepted
time: 3ms
memory: 3596kb

input:

7 10
118
1 8 235 740004
1 15 235 786710
1 6 235 339509
1 12 235 515467
1 12 235 519742
1 15 235 977904
2 9 235 847138
2 17 235 44976
2 12 235 838140
2 12 235 972095
3 18 235 923147
3 13 235 370884
3 12 235 321636
3 11 235 194699
3 8 235 136353
3 2 235 672512
3 5 235 581774
3 18 235 792723
4 12 235 7...

output:

3475028895

result:

ok single line: '3475028895'

Test #16:

score: 0
Accepted
time: 3ms
memory: 3628kb

input:

5 10
64
1 13 395 89457
1 6 395 913269
1 3 395 533823
1 12 395 299412
2 8 395 885467
3 2 395 846694
3 8 395 840291
3 12 395 726864
5 1 395 559239
5 16 395 509686
5 15 395 510639
6 14 395 682284
6 15 395 305150
6 7 395 950255
6 3 395 722333
6 9 395 116741
6 16 395 920155
6 4 395 821632
7 1 395 433404
...

output:

6069924315

result:

ok single line: '6069924315'

Test #17:

score: 0
Accepted
time: 21ms
memory: 3708kb

input:

10 100
1000
1 54 9819 1668
1 81 3777 20940
1 16 30269 2050
1 31 13427 23725
1 32 6599 8628
1 31 30793 12521
2 36 2162 4829
2 47 20876 12568
2 12 21693 4061
2 31 11742 18950
2 101 15898 28870
2 92 21119 18351
2 77 18266 2818
2 85 36379 7941
2 9 35124 15690
2 80 40246 10253
2 46 9197 21007
3 73 8500 1...

output:

661593355500

result:

ok single line: '661593355500'

Test #18:

score: 0
Accepted
time: 2ms
memory: 3632kb

input:

10 100
105
9 34 25926 912
9 57 33081 25091
9 39 3649 2162
9 104 30310 11335
10 95 27339 7874
11 50 13659 5458
12 69 9990 9716
13 101 26589 3367
14 47 24838 22444
15 106 40274 14642
16 96 24311 26793
17 79 23796 27238
18 22 20190 4370
18 89 18914 2273
19 56 3192 13244
20 87 14161 862
20 74 16958 5461...

output:

351353481838

result:

ok single line: '351353481838'

Test #19:

score: 0
Accepted
time: 2ms
memory: 3572kb

input:

10 100
105
8 12 6959 5029
9 72 15615 21776
9 101 2561 23907
9 96 3041 15777
9 16 35908 30026
9 82 26864 9409
10 24 2580 23023
11 45 25107 18709
12 59 3719 7360
13 35 35178 2211
13 98 19813 12857
14 24 2155 22822
15 54 39002 25195
17 92 29148 3168
18 101 2614 245
19 23 18095 6863
19 98 35004 25409
20...

output:

2910829273500

result:

ok single line: '2910829273500'

Test #20:

score: 0
Accepted
time: 4ms
memory: 3624kb

input:

10 100
105
9 25 1357 17445
9 111 32897 15253
9 106 34101 27343
9 49 12454 16389
9 31 24152 20654
9 101 19805 6191
10 83 14410 1991
10 47 15508 29771
10 67 3170 13515
11 72 10194 29007
11 88 1650 20037
12 93 38908 12749
12 73 26705 8226
13 35 39731 25833
14 111 23891 28334
14 75 19611 16710
14 100 35...

output:

3226693744086

result:

ok single line: '3226693744086'

Test #21:

score: 0
Accepted
time: 0ms
memory: 3628kb

input:

10 100
105
9 79 15386 20705
10 105 8983 27599
10 42 25965 16705
11 71 30911 16221
12 50 18254 1346
12 101 20072 21084
12 67 28760 161
13 94 39193 20489
13 32 20335 2600
13 56 15333 18568
14 74 18089 9132
14 90 32674 26716
15 40 40280 2885
16 37 23297 25843
16 108 28024 9150
17 109 24527 9801
17 45 3...

output:

796154202240

result:

ok single line: '796154202240'

Test #22:

score: 0
Accepted
time: 5ms
memory: 3620kb

input:

10 100
105
9 79 6848 8908
10 42 38257 8336
11 14 5752 5108
11 66 11191 19974
12 14 21997 18110
12 90 18633 13432
12 85 18988 10202
12 97 31866 28612
12 46 35618 1010
12 37 15800 22071
13 28 23258 887
13 77 33247 4596
13 26 4515 742
13 93 34728 4061
13 99 17423 22797
14 84 9342 4240
14 54 26840 789
1...

output:

77666869277

result:

ok single line: '77666869277'

Test #23:

score: 0
Accepted
time: 22ms
memory: 3596kb

input:

10 100
1000
1 94 11847 318
1 4 9324 10153
1 69 21264 6867
1 2 10393 6652
2 55 39357 16843
2 43 25064 9132
2 35 14756 14095
2 39 34982 19065
2 6 17004 21991
2 1 25365 4137
2 65 4251 27935
2 3 7817 22875
2 7 8656 20841
3 27 17530 20112
3 9 15231 16261
3 37 24649 3759
3 37 15851 15532
3 107 4560 4244
3...

output:

430285535

result:

ok single line: '430285535'

Test #24:

score: 0
Accepted
time: 0ms
memory: 3672kb

input:

0 10
30
1 11 527597 1
1 9 295111 1
2 8 170640 1
2 9 21904 1
2 11 217326 1
2 4 382467 1
3 8 695201 1
3 4 881445 1
3 10 629480 1
3 7 356118 1
3 11 362050 1
4 2 323640 1
4 6 195480 1
4 3 986288 1
4 10 129385 1
5 11 425795 1
6 11 791337 1
6 11 298105 1
6 4 42367 1
7 10 343425 1
7 3 179099 1
8 9 956180 1...

output:

16652545

result:

ok single line: '16652545'

Test #25:

score: 0
Accepted
time: 18ms
memory: 3692kb

input:

10 100
1000
1 105 258062 165527
1 23 47102 132075
1 77 895234 100458
1 108 590890 349502
1 61 281530 181989
1 67 879649 189854
1 74 612014 862720
1 2 777353 634062
1 81 934693 381787
1 65 40009 739794
1 90 333339 735021
2 60 887637 2429
2 38 922646 263938
2 62 124728 341935
2 92 117476 378163
2 56 3...

output:

509530306030604

result:

ok single line: '509530306030604'

Test #26:

score: 0
Accepted
time: 16ms
memory: 3656kb

input:

10 100
1000
1 96 302740 857848
1 57 76445 348323
1 70 476036 110006
2 11 263284 548530
2 56 95725 938004
2 56 692297 958348
2 9 240255 505897
2 25 999920 670783
2 19 832049 714070
2 97 162243 177599
2 59 437069 802088
3 87 599841 822572
3 110 115250 288579
3 79 724704 830741
3 48 842234 30674
3 48 8...

output:

414600556794138

result:

ok single line: '414600556794138'

Test #27:

score: 0
Accepted
time: 12ms
memory: 3640kb

input:

10 100
1000
1 107 0 992664
1 65 4 925929
1 24 3 903255
1 104 0 903829
1 11 4 943888
1 24 3 973181
1 94 0 912597
1 33 0 937518
2 15 3 909582
2 16 3 981181
2 96 2 930161
2 104 1 909821
2 24 1 910698
2 92 0 972863
2 24 1 903597
2 4 2 909645
2 71 4 973814
3 89 3 969011
3 50 3 944449
3 40 4 987424
3 93 0...

output:

41750530005

result:

ok single line: '41750530005'

Test #28:

score: 0
Accepted
time: 26ms
memory: 3576kb

input:

10 100
1000
1 87 10557 29364
1 35 28286 16905
1 65 7407 23097
1 44 8139 29701
1 47 14121 334
1 86 13645 16955
1 39 33945 6808
1 35 34613 10285
1 23 13082 20232
2 39 13603 21016
2 57 6257 10813
2 94 7305 23742
2 41 34648 11125
2 44 30576 2678
2 48 18935 14925
2 70 12385 12094
2 18 20047 3323
2 66 109...

output:

724608474326

result:

ok single line: '724608474326'

Test #29:

score: 0
Accepted
time: 25ms
memory: 3576kb

input:

10 100
1000
1 98 848210 138098
1 86 348491 2763
1 83 381149 21708
1 64 198880 680277
2 83 24135 834628
2 85 245878 697601
2 98 849278 708270
2 53 900021 781810
2 17 667050 901931
2 23 638134 316641
2 7 866354 479441
2 16 304368 58035
3 57 117918 625608
3 68 88113 724414
3 52 605945 184024
3 16 37196...

output:

415881249591156

result:

ok single line: '415881249591156'

Test #30:

score: 0
Accepted
time: 22ms
memory: 3616kb

input:

10 100
1000
1 96 596954 304133
1 109 485030 922946
1 41 380080 971257
1 60 976380 432182
1 107 873075 504417
1 59 763285 137950
1 45 231560 341967
1 10 156264 96577
1 105 502258 870590
1 66 992960 693665
1 37 900649 716306
1 71 183696 85978
2 83 199348 441676
2 91 186075 906189
2 86 504368 940445
2 ...

output:

470419401703180

result:

ok single line: '470419401703180'

Test #31:

score: 0
Accepted
time: 18ms
memory: 3596kb

input:

10 100
1000
1 19 4 940216
1 66 3 981844
1 35 4 966759
1 39 0 920341
1 38 3 949710
1 12 1 942850
1 54 0 944211
1 81 0 977704
1 56 4 949278
1 95 1 991143
2 97 0 900387
2 72 2 980869
2 66 3 925480
2 101 2 998930
2 70 4 999919
2 104 3 918725
2 53 1 931952
2 42 3 959083
2 33 3 957974
3 70 3 985217
3 37 4...

output:

41058933339

result:

ok single line: '41058933339'

Test #32:

score: 0
Accepted
time: 17ms
memory: 3728kb

input:

10 100
1000
1 7 993861 3
1 92 977952 1
1 47 927739 5
1 39 922504 2
1 102 946925 5
1 99 913612 4
1 101 900902 3
1 78 995574 1
1 7 997260 1
1 53 997391 1
2 40 976821 3
2 89 954564 1
2 52 927222 4
2 95 943131 1
2 28 920029 3
2 78 920680 1
2 55 955022 2
2 1 991489 1
3 38 945704 4
3 12 936013 5
3 58 9779...

output:

11641531926

result:

ok single line: '11641531926'

Test #33:

score: 0
Accepted
time: 2ms
memory: 3684kb

input:

0 100
100
1 2 0 1000000
2 3 0 1000000
3 4 0 1000000
4 5 0 1000000
5 6 0 1000000
6 7 0 1000000
7 8 0 1000000
8 9 0 1000000
9 10 0 1000000
10 11 0 1000000
11 12 0 1000000
12 13 0 1000000
13 14 0 1000000
14 15 0 1000000
15 16 0 1000000
16 17 0 1000000
17 18 0 1000000
18 19 0 1000000
19 20 0 1000000
20 ...

output:

100000000

result:

ok single line: '100000000'

Test #34:

score: 0
Accepted
time: 3ms
memory: 3680kb

input:

0 100
100
1 2 1000000 1
2 3 1000000 1
3 4 1000000 1
4 5 1000000 1
5 6 1000000 1
6 7 1000000 1
7 8 1000000 1
8 9 1000000 1
9 10 1000000 1
10 11 1000000 1
11 12 1000000 1
12 13 1000000 1
13 14 1000000 1
14 15 1000000 1
15 16 1000000 1
16 17 1000000 1
17 18 1000000 1
18 19 1000000 1
19 20 1000000 1
20 ...

output:

1000000

result:

ok single line: '1000000'

Test #35:

score: 0
Accepted
time: 3ms
memory: 3576kb

input:

0 10
30
1 4 1 757413
1 3 1 89029
1 9 1 474323
1 2 1 883073
2 10 1 495799
2 4 1 797333
2 9 1 854187
2 9 1 520474
3 11 1 978279
3 10 1 657125
4 5 1 899221
4 7 1 946995
4 6 1 678310
5 8 1 405654
6 9 1 931079
6 4 1 862685
6 11 1 110153
6 2 1 887083
7 9 1 175352
7 11 1 808991
7 11 1 867200
7 11 1 129890
...

output:

7559695

result:

ok single line: '7559695'

Test #36:

score: 0
Accepted
time: 3ms
memory: 3624kb

input:

0 24
100
1 2 213344 1
1 24 576326 1
1 21 246772 1
1 16 938936 1
1 23 957577 1
1 11 876358 1
1 8 70857 1
2 18 697849 1
2 3 92813 1
2 8 69150 1
2 3 126753 1
2 16 602507 1
2 25 17075 1
3 15 778953 1
3 15 965281 1
3 1 643334 1
3 12 577253 1
4 25 686204 1
4 17 122283 1
4 23 427411 1
4 23 131164 1
5 24 89...

output:

7339767

result:

ok single line: '7339767'

Test #37:

score: 0
Accepted
time: 3ms
memory: 3688kb

input:

0 67
100
1 68 382190 1000000
2 21 366561 1000000
2 67 693549 1000000
3 10 549775 1000000
3 47 788684 1000000
4 54 298467 1000000
4 20 637615 1000000
4 44 666994 1000000
4 63 503160 1000000
4 18 495440 1000000
4 51 427769 1000000
5 49 97297 1000000
5 60 553335 1000000
5 19 249002 1000000
6 34 411100 ...

output:

689311175500000

result:

ok single line: '689311175500000'

Test #38:

score: 0
Accepted
time: 4ms
memory: 3600kb

input:

0 90
100
1 43 500000 195440
2 5 500000 221171
2 33 500000 670266
2 21 500000 330247
2 85 500000 584954
3 84 500000 865073
4 56 500000 906027
4 55 500000 237671
5 81 500000 591542
5 82 500000 361432
5 45 500000 46695
5 66 500000 547650
5 50 500000 791218
5 35 500000 820958
5 74 500000 569746
6 58 500...

output:

22974045000000

result:

ok single line: '22974045000000'

Test #39:

score: 0
Accepted
time: 3ms
memory: 3624kb

input:

0 6
1000
1 5 492371 74854
1 4 925981 74854
1 2 411435 74854
1 2 68102 74854
1 6 418420 74854
1 4 376762 74854
1 6 558476 74854
1 5 712542 74854
1 3 51998 74854
1 4 717110 74854
1 2 169199 74854
1 2 485383 74854
1 5 481111 74854
1 7 961841 74854
1 7 299990 74854
1 6 863399 74854
1 5 207310 74854
1 3 ...

output:

18609265805

result:

ok single line: '18609265805'

Test #40:

score: 0
Accepted
time: 3ms
memory: 3644kb

input:

0 8
1000
1 2 891428 208330
1 3 920928 208330
1 4 145213 208330
1 4 789768 208330
1 7 990205 208330
1 7 527755 208330
1 4 560161 208330
1 7 972328 208330
1 5 176652 208330
1 5 828552 208330
1 5 159734 208330
1 9 341181 208330
1 8 460450 208330
1 5 605213 208330
1 5 1835 208330
1 9 344608 208330
1 9 1...

output:

33068887556

result:

ok single line: '33068887556'