QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#327314#4805. Grammy SortinglefyWA 2ms7872kbC++142.2kb2024-02-14 21:27:022024-02-14 21:27:02

Judging History

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

  • [2024-02-14 21:27:02]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:7872kb
  • [2024-02-14 21:27:02]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int N=1010;
int a[N],A,B,vis[N];
vector<int>e[N];
int fa[N],dfn[N],low[N],id[N],tot,flag;
void Tarjan(int x){
    dfn[x]=low[x]=++tot,id[tot]=x;
    if(x==A){
        fa[B]=A;
        Tarjan(B);
    }
    // cout<<x<<"  "<<fa[x]<<"*\n";
    for(int v:e[x]){
        if(!dfn[v]){
            if(x==A)flag=1;
            fa[v]=x;
            Tarjan(v);
            low[x]=min(low[x],low[v]);
            if(low[v]>=dfn[x])flag=1;
        }else low[x]=min(low[x],dfn[v]);
    }
}
vector<int>to[N];
int in[N];
int tp[N],mp[N][N];
int main() {
    int n,m;
    scanf("%d%d%d%d",&n,&m,&A,&B);
    for(int i=1;i<=n;i++)scanf("%d",&a[i]);
    for(int i=1;i<=m;i++){
        int x,y;
        scanf("%d%d",&x,&y);
        mp[x][y]=mp[y][x]=1;
        e[x].push_back(y);
        e[y].push_back(x);
    }
    Tarjan(A);
    if(flag){printf("-1");return 0;}
    for(int i=1;i<=n;i++)in[fa[i]]++;
    queue<int>q;tot=0;tp[++tot]=A;vector<int>lf;
    for(int i=1;i<=n;i++)if(i!=A&&i!=B&&!in[i]){
        lf.push_back(i);
        q.push(i);
        vector<int>now;now.push_back(A);
        for(int x=i;;x=fa[x]){
            if(n>=200&&!mp[x][fa[x]])cout<<x<<"\n";
            if(vis[x])break;vis[x]=1;
            now.push_back(x);
            to[x]=now;
            if(x==B)break;
        }
        // cout<<"\n";
    }
    while(!q.empty()){
        int x=q.front();q.pop();if(x==A)break;
        in[fa[x]]--;if(!in[fa[x]])q.push(fa[x]);
        tp[++tot]=x;
        // cout<<x<<"";
    }
    printf("%d\n",n-1);
    for(int i=n;i>1;i--){
        int x=tp[i],sz=0;
        if(i==2)for(int v:lf)if(a[v]<a[x])x=v;
        if(i!=n)for(int v=fa[x];v!=A;v=fa[v],sz++)if(a[A]<a[v])break;
        printf("%d ",(int)to[x].size()+sz);
        int tmp=a[A];
        
        for(int i=0;i<(int)to[x].size()-1;i++)a[to[x][i]]=a[to[x][i+1]],printf("%d ",to[x][i]);
        printf("%d",x);
        if(sz){
            for(int i=1;i<=sz;i++){
                a[x]=a[fa[x]];
                x=fa[x];
                printf(" %d",x);
            }
        }
        a[x]=tmp;
        printf("\n");
    }
    return 0;
}

詳細信息

Test #1:

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

input:

5 6 1 2
1 2 3 4 5
1 3
2 3
1 4
2 4
1 5
3 5

output:

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

result:

ok ok

Test #2:

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

input:

4 3 1 2
1 4 2 3
1 4
2 4
3 4

output:

-1

result:

ok ok

Test #3:

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

input:

1000 2000 690 321
822 159 322 907 204 349 422 568 486 775 516 80 996 532 866 134 967 772 421 10 46 878 570 958 62 859 853 32 657 868 145 767 600 748 112 938 343 404 677 116 43 690 92 300 380 942 155 5 870 522 628 464 956 25 30 107 241 708 526 846 272 658 670 160 979 707 829 580 452 338 980 88 166 13...

output:

-1

result:

ok ok

Test #4:

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

input:

1000 2000 818 462
259 437 217 750 664 585 779 875 6 99 642 145 157 303 526 84 309 959 704 970 973 542 811 832 199 516 397 325 907 485 696 559 999 335 301 974 177 426 862 520 297 446 420 990 534 32 137 376 804 35 14 754 87 227 67 826 183 930 831 668 874 720 4 641 304 54 313 393 122 427 658 363 323 19...

output:

-1

result:

ok ok

Test #5:

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

input:

1000 2000 242 10
265 105 286 761 436 727 365 271 87 34 104 263 400 74 103 623 976 390 626 482 797 204 712 412 641 399 942 765 805 585 131 754 165 168 51 546 319 427 784 12 920 380 892 246 422 184 616 611 516 396 530 682 653 907 924 474 167 954 56 391 401 409 55 26 497 969 417 934 994 780 768 309 27 ...

output:

-1

result:

ok ok

Test #6:

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

input:

1000 2000 666 150
671 295 803 55 457 427 489 783 578 431 481 689 30 716 799 624 981 173 298 825 339 563 705 71 958 679 292 317 385 808 929 584 662 19 101 901 118 404 931 11 634 113 763 43 785 493 290 358 976 961 695 147 675 368 107 211 638 989 232 23 996 458 850 652 812 68 413 56 960 490 330 715 496...

output:

-1

result:

ok ok

Test #7:

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

input:

1000 2000 794 995
651 17 422 858 76 632 96 467 841 151 645 722 557 653 146 413 627 497 683 824 267 67 923 748 164 915 385 78 249 228 744 227 253 137 359 1 108 679 380 648 35 959 126 804 802 474 867 356 507 291 128 776 283 974 138 903 45 173 813 773 900 243 437 178 839 260 342 425 221 861 524 732 505...

output:

-1

result:

ok ok

Test #8:

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

input:

500 2000 361 270
1 416 382 489 19 269 340 435 497 5 276 316 358 332 137 63 257 395 73 61 496 181 119 100 149 304 409 102 191 264 279 286 386 200 82 455 250 366 154 135 273 164 108 398 344 400 109 498 99 369 172 411 193 471 327 171 64 218 123 107 143 295 45 350 294 371 59 432 114 252 442 69 244 392 2...

output:

-1

result:

ok ok

Test #9:

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

input:

500 2000 81 410
199 182 230 436 475 300 32 479 181 329 228 338 351 167 395 36 232 411 356 412 314 317 467 464 257 405 162 438 426 483 43 435 461 319 361 343 15 381 401 91 156 493 447 37 172 470 268 117 299 274 18 473 275 367 98 277 133 127 205 35 45 220 204 140 290 72 402 27 382 302 129 389 318 416 ...

output:

-1

result:

ok ok

Test #10:

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

input:

500 2000 209 254
272 8 472 466 136 277 204 38 342 3 421 338 23 408 273 320 151 391 290 94 44 215 179 84 16 218 251 281 285 85 433 133 257 217 55 138 143 367 390 488 209 237 465 326 161 198 36 175 485 28 178 458 283 308 240 241 443 306 207 484 154 279 304 435 431 224 226 449 210 25 53 375 141 146 177...

output:

-1

result:

ok ok

Test #11:

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

input:

500 2000 133 99
414 240 21 246 40 11 459 205 20 260 114 282 53 43 468 108 301 212 209 476 164 171 206 261 490 296 251 170 31 39 462 272 386 172 29 41 359 452 69 338 289 214 268 265 208 375 103 192 361 288 112 355 86 342 488 146 101 79 255 303 333 12 317 22 50 431 181 429 162 169 185 187 161 494 486 ...

output:

-1

result:

ok ok

Test #12:

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

input:

500 2000 261 443
70 479 170 186 15 223 8 77 337 123 349 295 437 230 265 365 54 444 375 308 169 281 333 297 176 376 26 366 172 274 20 49 224 191 4 370 299 406 338 328 119 470 81 56 126 11 92 347 471 257 83 48 445 438 494 271 52 1 331 196 408 469 473 85 413 235 289 110 477 309 155 287 50 319 354 250 4...

output:

-1

result:

ok ok

Test #13:

score: -100
Wrong Answer
time: 2ms
memory: 6628kb

input:

200 2000 164 195
139 155 66 190 47 132 198 171 123 38 196 43 181 163 126 22 30 6 46 149 117 8 81 100 141 98 37 115 59 200 72 106 74 44 75 160 183 186 189 174 127 26 152 182 4 113 80 158 99 56 118 133 33 10 104 173 78 65 70 51 91 83 130 52 191 73 187 60 63 49 36 17 151 150 140 164 9 58 84 3 14 138 17...

output:

195
199
177 164 5 103 83 148 109 10 43 60 167 47 138 129 158 176 2 91 56 169 72 136 8 100 92 62 145 175 196 163 33 46 50 84 155 9 85 34 55 133 139 74 6 126 187 59 3 168 93 116 41 71 117 165 78 28 151 66 160 132 166 68 65 143 88 48 99 19 105 13 190 87 104 178 191 110 150 17 37 179 134 197 186 146 49 ...

result:

wrong answer a_1 != A at operation #1