UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#183596#3295. E.Space 的通信题gaojieming10013235ms69680kbC++112.2kb2023-08-09 11:51:592023-08-09 12:37:49

answer

#include<bits/stdc++.h>
#define ll long long
#define il inline
#define pn putchar('\n')
#define maxint 2147483647
#define min(x,y) (x<y?x:y)
#define max(x,y) (x>y?x:y)
#define maxn 23
#define int ll
using namespace std;
int n,m,cntb,cntc;
int a[maxn][maxn],f[1<<maxn],b[maxn][1<<13],c[maxn][1<<13];
il void print(int x,int d=n)
{
    if(!d)return;
    printf("%d",x&1);
    print(x>>1,d-1);
}
signed main()
{
    #ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
    #endif
    scanf("%lld%lld",&n,&m);
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
            a[i][j]=2147483647;
    while(m--)
    {
        int u,v,w;
        scanf("%lld%lld%lld",&u,&v,&w);
        a[u][v]=a[v][u]=w;
    }
    for(int i=1;i<=n;i++)
        a[i][i]=0;
    memset(f,0x3f,sizeof f);
    for(int i=1,j=1;i<=n;i++,j<<=1)
        f[j]=0;
    memset(b,0x3f,sizeof b);
    for(int S=0,lim=(1<<(n>>1));S<lim;S++)
    {
        for(int i=1;i<=n;i++)
        {
            int x=S;
            for(int j=1;j<=n/2;j++,x>>=1)
                if(x&1)
                    b[i][S]=min(b[i][S],a[i][j]);
        }
    }
    memset(c,0x3f,sizeof c);
    for(int S=0,lim=(1<<(n+1>>1));S<lim;S++)
    {
        for(int i=1;i<=n;i++)
        {
            int x=S;
            for(int j=n/2+1;j<=n;j++,x>>=1)
                if(x&1)
                    c[i][S]=min(c[i][S],a[i][j]);
        }
    }
    for(int S=0,lim=(1<<n);S<lim;S++)
    {
        int x=S,lef=S&((1<<n/2)-1);
        int rig=S-lef>>n/2;
        cntb=cntc=0;
        for(int i=1;i<=n;i++,x>>=1)
            if(!(x&1))
                f[S|(1<<i-1)]=min(f[S|(1<<i-1)],f[S]+min(b[i][lef],c[i][rig]));
    }
    for(int S=(1<<n)-1;~S;S--)
    {
        int x=S;
        for(int i=1;i<=n;i++,x>>=1)
            if(!(x&1))
                f[S]=min(f[S],f[S|(1<<i-1)]);
    }
    // for(int S=0,lim=(1<<n);S<lim;S++)
    //     print(S),printf(" %lld\n",f[S]);
    scanf("%lld",&m);
    while(m--)
    {
        int k,x=0;
        scanf("%lld",&k);
        while(k--)
        {
            int y;
            scanf("%lld",&y);
            x|=1<<y-1;
        }
        printf("%lld\n",f[x]);
    }
    return 0;
}

详细

小提示:点击横条可展开更详细的信息

Subtask #1:

score: 21
Accepted

Test #1:

score: 21
Accepted
time: 34ms
memory: 69672kb

input:

18 10
16 13 343227
8 12 887576
18 14 892337
6 16 282222
17 2 5571501
3 6 904832
9 15 913133
17 14 44...

output:

6450089014
15033273105
15042441459
10746243362
15040661546
6443338517
6442450941
4294967294
85899345...

result:

ok 100 numbers

Test #2:

score: 0
Accepted
time: 324ms
memory: 69680kb

input:

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

output:

15032385529
21474836470
2147483647
23622320117
17179869176
32212254705
36507221999
25769803764
23622...

result:

ok 100 numbers

Test #3:

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

input:

15 10
8 10 226688
6 15 969370
11 5 359456
13 8 285516
6 1 280719
12 14 288499
6 3 136821
14 8 217480...

output:

2150496798
4297188950
6442956920
4297013164
6445614876
10741007490
10740074019
4297218853
1074003812...

result:

ok 100 numbers

Test #4:

score: 0
Accepted
time: 39ms
memory: 69676kb

input:

18 10
15 18 749719
10 8 893577
9 10 128731
7 10 923595
18 12 190863
12 8 532430
14 11 316196
14 5 69...

output:

10741139398
6444501534
2150787057
12890988617
10741254903
8595271604
8595097728
4298630086
859514287...

result:

ok 100 numbers

Test #5:

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

input:

10 10
4 3 58357
6 2 792434
4 10 678987
10 2 231624
1 6 673671
1 8 407962
1 7 774471
9 3 332936
5 7 1...

output:

2045684
1662506
3750234
1081633
1448142
3750234
3518610
3750234
2668601
3750234
2777712
3750234
9689...

result:

ok 100 numbers

Test #6:

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

input:

7 10
2 5 7748298
3 1 3157038
6 4 197616
5 4 809282
7 6 366933
3 4 99323
7 3 64632
7 2 305607
6 5 728...

output:

4553013
3824216
4247406
370239
1278844
3626600
1278844
4553013
469562
99323
3824216
809282
3824216
4...

result:

ok 100 numbers

Test #7:

score: 0
Accepted
time: 11ms
memory: 69676kb

input:

5 10
1 2 139082
5 1 632382
4 1 744091
4 3 46825
5 2 161496
2 3 516208
3 5 623520
5 4 791932
2 4 1322...

output:

374708
139082
374708
374708
340582
334704
213212
374708
300578
34126
213212
179086
340582
300578
374...

result:

ok 100 numbers

Test #8:

score: 0
Accepted
time: 477ms
memory: 69672kb

input:

21 7
19 11 268148
9 10 951666
14 8 318278
3 12 775855
21 18 778913
7 4 212484
13 21 6071797
100
19 1...

output:

25778862627
2147483647
2147483647
12885488308
25778862627
12885170030
27920592755
2147483647
2792562...

result:

ok 100 numbers

Test #9:

score: 0
Accepted
time: 477ms
memory: 69672kb

input:

21 2
12 13 674404
6 7 274426
100
2 4 18
11 9 21 5 2 14 6 19 13 10 15 1
9 7 18 19 14 11 2 17 20 9
15 ...

output:

2147483647
21474836470
17179869176
27917961815
21474836470
17180818006
23622594543
36507496425
36507...

result:

ok 100 numbers

Test #10:

score: 0
Accepted
time: 8ms
memory: 69672kb

input:

14 10
10 1 765425
9 10 850138
3 2 457708
6 13 833286
5 14 2935548
5 1 431254
2 14 4989649
6 11 33935...

output:

2147823004
8599602833
6452889797
2147483647
6450811340
4302562268
8599523306
4298334096
8902820
6446...

result:

ok 100 numbers

Subtask #2:

score: 33
Accepted

Test #11:

score: 33
Accepted
time: 475ms
memory: 69676kb

input:

21 180
15 20 926409
19 9 208231
9 20 466331
13 15 6624932
1 12 477710
5 17 17501
13 8 3102658
12 20 ...

output:

664923
289614
372673
318790
308499
580027
356373
362787
552288
503796
501937
181606
467477
546823
52...

result:

ok 100 numbers

Test #12:

score: 0
Accepted
time: 462ms
memory: 69676kb

input:

21 40
6 10 268727
4 1 845672
16 15 8829107
9 5 732688
8 6 3242475
15 2 960548
1 8 456272
8 5 482422
...

output:

1482345
2665382
2197987
196776
2261397
2511767
954273
2147978186
1428111
182758
834331
738473
567915...

result:

ok 100 numbers

Test #13:

score: 0
Accepted
time: 450ms
memory: 69672kb

input:

21 20
8 1 732144
15 3 227227
18 21 946840
20 3 906028
9 18 909717
3 21 798211
10 2 963737
2 20 97419...

output:

4298510725
5001383
2159979826
5510483
6789445
14633565
12575167
2159165928
5790046
4298517534
348675...

result:

ok 100 numbers

Test #14:

score: 0
Accepted
time: 227ms
memory: 69676kb

input:

20 60
19 8 144129
16 6 381040
15 14 717615
14 16 653479
8 13 348024
9 4 3553842
4 17 923421
11 9 160...

output:

1160896
2427433
796337
1499052
186925
2030378
2124723
770067
1537754
2235906
1179101
326818
628973
1...

result:

ok 100 numbers

Test #15:

score: 0
Accepted
time: 446ms
memory: 69672kb

input:

21 210
6 2 962290
12 6 7838395
15 8 616045
13 8 9249447
16 9 180861
21 1 851639
11 18 640082
2 8 856...

output:

681685
594630
256704
694664
785023
521473
626114
562959
321489
789964
623277
318104
791101
700957
18...

result:

ok 100 numbers

Test #16:

score: 0
Accepted
time: 456ms
memory: 69672kb

input:

21 190
9 20 651452
12 15 653502
19 2 2107785
14 15 11219
18 3 728585
13 12 994315
12 19 1189230
19 1...

output:

316150
293685
484329
418865
465774
164967
426015
748697
441543
755269
746097
334699
242713
650508
20...

result:

ok 100 numbers

Test #17:

score: 0
Accepted
time: 346ms
memory: 69676kb

input:

21 70
4 14 317436
18 17 309846
3 1 414849
5 10 209492
6 12 686429
20 4 837659
7 16 701826
6 17 58425...

output:

1395427
1058222
1023284
671330
1364011
816176
1467239
896531
1165083
1140189
443208
645592
1156312
1...

result:

ok 100 numbers

Test #18:

score: 0
Accepted
time: 331ms
memory: 69676kb

input:

21 30
6 14 210001
13 15 384827
20 4 535199
9 16 279052
20 19 192200
11 4 8882825
16 19 4022401
7 3 3...

output:

2147483647
2150004169
2150929496
869560
1856955
353335
2147483647
949060
2985106
1192572
2150044901
...

result:

ok 100 numbers

Test #19:

score: 0
Accepted
time: 38ms
memory: 69672kb

input:

18 100
3 9 359437
15 8 719691
13 12 718477
12 14 456901
13 11 6797531
13 2 675012
6 2 104217
10 17 7...

output:

397273
367239
696854
869789
450940
332133
860380
156030
401217
502192
625301
582612
361557
1246455
8...

result:

ok 100 numbers

Test #20:

score: 0
Accepted
time: 329ms
memory: 69676kb

input:

21 100
17 3 707306
21 1 4463514
13 19 858060
10 4 363970
9 1 856304
5 7 254140
16 10 753412
1 5 6392...

output:

1052484
1151183
1463799
1311636
1583615
539568
1706106
678928
788681
1501371
1411182
1122291
1764465...

result:

ok 100 numbers

Subtask #3:

score: 21
Accepted

Test #21:

score: 21
Accepted
time: 105ms
memory: 69672kb

input:

16 87
14 16 692179
12 16 884606
1 14 5781736
4 8 443881
9 13 991502
13 4 459353
13 2 142866
8 16 902...

output:

999972
600926
791649
547929
1034596
722785
805959
807273
1172865
1172865
985004
1172865
189511
49522...

result:

ok 100000 numbers

Test #22:

score: 0
Accepted
time: 98ms
memory: 69672kb

input:

16 60
1 10 683883
10 11 510895
16 15 733777
1 11 455555
14 8 880871
12 7 656534
3 7 438492
2 1 31570...

output:

1486510
1716547
2145411
2532679
2059884
2532679
395494
1690436
1948256
681041
375516
1688860
2517147...

result:

ok 100000 numbers

Test #23:

score: 0
Accepted
time: 144ms
memory: 69676kb

input:

16 40
4 11 911282
5 8 629324
16 6 390007
10 2 704842
12 14 341075
3 1 548881
16 5 592312
9 7 325872
...

output:

1507284
2963067
2673748
3815261
3632650
3242329
972105
1986978
2705630
2604096
5840125
5840125
58401...

result:

ok 100000 numbers

Test #24:

score: 0
Accepted
time: 187ms
memory: 69676kb

input:

16 120
6 5 5132412
2 11 295629
7 6 344600
3 11 994893
10 8 589332
3 13 872134
8 13 665905
9 2 353640...

output:

264693
979739
750672
548599
662854
185855
274517
1232776
1145620
639512
1087313
1000132
928429
63514...

result:

ok 100000 numbers

Test #25:

score: 0
Accepted
time: 186ms
memory: 69676kb

input:

16 15
11 10 318010
16 7 283779
8 7 336565
15 16 881391
8 13 233413
8 12 702911
7 15 24666
3 12 18547...

output:

6446223830
1889177
4294967294
6445563418
6446055715
4294967294
6445751376
4297023267
2150362711
6446...

result:

ok 100000 numbers

Test #26:

score: 0
Accepted
time: 186ms
memory: 69672kb

input:

16 5
12 14 626647
3 9 218008
13 1 518986
8 11 613037
6 2 344886
100000
12 4 3 11 1 13 5 12 7 9 14 16...

output:

17181232817
12885420868
6443063978
19329456379
6443582964
19328197478
17181564093
4294967294
1503408...

result:

ok 100000 numbers

Test #27:

score: 0
Accepted
time: 173ms
memory: 69676kb

input:

16 100
10 1 765425
15 14 850138
7 14 457708
4 6 181124
15 12 531971
3 6 824150
3 1 688579
5 13 39405...

output:

1257827
1301202
1668334
1078892
1569701
1628493
590004
1556725
1394342
1583380
700567
819041
1569701...

result:

ok 100000 numbers

Test #28:

score: 0
Accepted
time: 185ms
memory: 69676kb

input:

16 60
6 8 124490
10 13 9423144
8 9 388106
14 2 378111
13 2 779724
10 8 823592
14 5 319233
5 15 61732...

output:

3442475
2476268
3322194
1582595
1737397
3054960
570950
2662376
2107221
2333737
2686067
1212746
32980...

result:

ok 100000 numbers

Test #29:

score: 0
Accepted
time: 180ms
memory: 69676kb

input:

16 120
6 10 535
5 16 588301
12 15 684449
10 14 375219
15 6 324952
1 7 28759
8 1 463468
1 12 624072
1...

output:

301425
911129
911664
549511
576112
884528
911129
95029
884528
911664
274696
911664
276239
329143
529...

result:

ok 100000 numbers

Test #30:

score: 0
Accepted
time: 174ms
memory: 69672kb

input:

16 120
14 16 367058
2 5 702640
16 1 9406354
6 10 320583
5 10 348244
2 16 687216
6 13 921609
13 7 667...

output:

493145
1623058
1921354
1705823
677613
1236551
1498302
982435
728800
1362722
1032241
1482452
869550
1...

result:

ok 100000 numbers

Subtask #4:

score: 25
Accepted

Test #31:

score: 25
Accepted
time: 659ms
memory: 69672kb

input:

21 100
3 17 448157
6 16 732991
9 12 557802
1 11 177684
3 4 924650
5 3 565900
11 10 482255
13 9 15226...

output:

1429715
2360424
1162938
282833
1068991
1469992
2403797
1508001
2126809
1509884
2278327
1208007
18039...

result:

ok 100000 numbers

Test #32:

score: 0
Accepted
time: 661ms
memory: 69676kb

input:

21 210
8 1 7683813
2 8 455052
19 1 795392
14 12 790751
18 7 42367
13 18 144935
15 18 403091
10 20 88...

output:

1351887
554348
1600566
1530479
1479938
1582334
1212060
790252
1262283
1298301
1398544
1600566
162811...

result:

ok 100000 numbers

Test #33:

score: 0
Accepted
time: 666ms
memory: 69672kb

input:

21 210
1 5 602376
17 16 760958
9 12 418073
6 13 4030
20 14 5827851
1 9 126288
11 12 4449232
19 6 323...

output:

199539
1207907
334917
44554
629138
20995
434964
872356
562309
442539
142384
1064938
971882
399090
35...

result:

ok 100000 numbers

Test #34:

score: 0
Accepted
time: 661ms
memory: 69672kb

input:

21 150
6 2 896757
2 12 204565
20 21 386062
1 12 451370
1 6 307045
3 17 608426
16 19 567409
19 15 437...

output:

1998677
1497085
2002623
561677
1325740
2365912
975705
436943
884261
2526250
796659
2526250
1691094
2...

result:

ok 100000 numbers

Test #35:

score: 0
Accepted
time: 680ms
memory: 69676kb

input:

21 100
20 19 909221
20 12 748521
10 2 522827
16 13 462333
12 8 353569
21 1 843344
5 2 329430
4 7 158...

output:

566311
771699
1789593
1937104
727471
2332207
464740
292650
1077754
2332207
395956
1086342
19563
1510...

result:

ok 100000 numbers

Test #36:

score: 0
Accepted
time: 666ms
memory: 69672kb

input:

21 80
9 18 7718336
18 20 742622
21 3 330496
13 8 2615285
20 16 434370
15 5 792990
6 16 467895
13 21 ...

output:

2672150
3530167
1602432
3201566
2836548
3610080
3024066
1459579
157371
2190977
2036883
1458955
15022...

result:

ok 100000 numbers

Test #37:

score: 0
Accepted
time: 675ms
memory: 69672kb

input:

21 40
20 1 220623
18 17 266269
4 7 6764250
18 4 6171132
3 16 620336
20 13 923480
17 9 403915
15 13 4...

output:

1830207
2150247390
1849599
3231341
2148682696
81013
2151931503
1270819
2152005495
193705
2150511275
...

result:

ok 100000 numbers

Test #38:

score: 0
Accepted
time: 684ms
memory: 69676kb

input:

21 20
5 7 974105
15 13 723447
4 2 270827
6 1 896948
7 10 249030
11 21 121005
15 20 7971858
16 4 5480...

output:

763286
2161734206
6456920265
2150729528
2147483647
6455420875
4310287368
2147483647
2157363562
64576...

result:

ok 100000 numbers

Test #39:

score: 0
Accepted
time: 650ms
memory: 69672kb

input:

21 1
15 17 219341
100000
14 10 17 4 15 6 20 5 18 16 13 2 21 9 14
10 20 1 9 12 15 8 2 16 10 13
19 4 5...

output:

25770023105
19327352823
36507441340
10737637576
6442450941
30064771058
10737418235
8589934588
300649...

result:

ok 100000 numbers

Test #40:

score: 0
Accepted
time: 674ms
memory: 69672kb

input:

21 90
15 6 528449
7 19 259183
3 19 5760138
15 18 365465
21 16 1721112
11 10 772216
12 10 2341213
7 2...

output:

2917449
3039270
2704691
2515266
2161886
900168
2987652
1452330
2288949
920873
1335259
1599440
263951...

result:

ok 100000 numbers