QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#36382#1957. Friendship Graphsyyf_0404WA 101ms9716kbC++1.3kb2022-06-27 14:25:432022-06-27 14:25:46

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-06-27 14:25:46]
  • 评测
  • 测评结果:WA
  • 用时:101ms
  • 内存:9716kb
  • [2022-06-27 14:25:43]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
int fa[2005], n, m, graph[1005][1005], vis[1005], tot, sz[1005], dp[1005][2005];
int fnd(int x)
{
    if(fa[x] == x) return x;
    return fa[x] = fnd(fa[x]);
}
void cup(int x, int y)
{
    x = fnd(x), y = fnd(y);
    fa[y] = x;
}
int main()
{
    scanf("%d%d", &n, &m);
    memset(vis, -1, sizeof(vis));
    for(int i = 1; i <= 2 * n; i++)
        fa[i] = i;
    for(int i = 1, u, v; i <= m; i++){
        scanf("%d%d", &u, &v);
        graph[u][v] = graph[v][u] = 1;
    }
    for(int i = 1; i <= n; i++)
        for(int j = i + 1; j <= n; j++)
            if(!graph[i][j]){
                if(fnd(i) == fnd(j)){
                    printf("-1\n");
                    return 0;
                }
                cup(i, j + n); cup(j, i + n);
            }
    for(int i = 1; i <= n; i++){
        if(!~vis[fnd(i)] && !~vis[fnd(i + n)])
            vis[fnd(i)] = tot++;
        if(~vis[fnd(i)]) sz[vis[fnd(i)]]++;
        else sz[vis[fnd(i + n)]]--;
    }
    dp[0][n] = 1;
    for(int i = 0; i < tot; i++)
        for(int j = 0; j <= 2 * n; j++)
            if(dp[i][j])
                dp[i + 1][j + sz[i]] = dp[i + 1][j - sz[i]] = 1;
    int ans = 0;
    while(!dp[tot][n + ans]) ans++;
    printf("%d\n", ans);
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 101ms
memory: 9700kb

input:

1000 499000
20 615
260 390
779 37
13 563
650 605
358 684
783 370
162 90
379 662
88 208
458 371
178 3
590 762
455 514
738 641
270 805
205 881
205 315
837 54
976 579
519 532
982 669
563 804
648 274
268 293
182 392
337 772
961 603
294 607
546 772
189 218
702 266
515 610
691 965
643 235
509 193
184 302
...

output:

0

result:

ok single line: '0'

Test #2:

score: 0
Accepted
time: 84ms
memory: 9704kb

input:

1000 498999
35 65
880 835
501 309
590 758
882 857
356 493
43 623
644 637
361 785
58 317
26 11
595 521
723 629
611 36
789 29
30 650
426 475
852 862
667 137
677 173
656 44
457 279
680 567
789 989
368 873
510 721
128 584
835 956
419 779
607 568
317 790
932 580
336 400
74 265
772 855
939 816
448 883
381...

output:

2

result:

ok single line: '2'

Test #3:

score: 0
Accepted
time: 92ms
memory: 9716kb

input:

1000 498998
667 721
880 868
426 900
882 839
789 440
590 395
356 847
852 758
35 648
26 723
611 329
644 560
723 45
595 813
501 338
58 762
30 302
43 340
361 734
74 863
128 433
656 196
677 188
932 651
835 603
368 568
336 105
317 225
457 350
419 771
607 545
789 31
772 465
510 542
680 888
504 445
884 999
...

output:

2

result:

ok single line: '2'

Test #4:

score: -100
Wrong Answer
time: 80ms
memory: 7736kb

input:

1000 499499
552 449
897 36
561 770
188 194
233 385
689 608
814 604
386 789
440 778
51 295
368 726
835 647
182 31
387 250
202 887
607 184
189 192
54 774
252 403
562 109
878 528
258 449
823 460
619 906
952 96
69 383
630 81
474 996
273 651
749 270
682 976
147 209
287 612
402 108
575 479
864 462
1000 72...

output:

990

result:

wrong answer 1st lines differ - expected: '0', found: '990'