UOJ Logo

NOI.AC

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#205494#3657. 二分图Daniel1024100471ms7380kbC++1.2kb2024-07-07 12:12:492024-07-07 13:19:41

answer

#include<bits/stdc++.h>
using namespace std;
int a, b, m;
vector<int>t[100005];
int have[100005];
int to[100005];
signed main(){
    // freopen("ex_data3.in", "r", stdin);
    cin >> a >> b >> m;
    for(int i = 1; i <= m; i++){
        int x, y;
        scanf("%d%d", &x, &y);
        if(x == a)to[y] ^= 1;
        else t[x].push_back(y);
    }
    for(int i = 1; i < a; i++){
        int len = t[i].size();
        for(int j = 0; j < len; j++){
            // to[t[i][j]] ^= 1;
            // to[t[i][j + 1]] ^= 1;
            have[i] ^= 1;
            to[t[i][j]] ^= 1;
            to[b] ^= 1;
        }
    }
    int ans = 0;
    int s1 = 0, s2 = 0;
    for(int i = 1; i < a; i++)s1 += have[i];
    for(int i = 1; i <= b; i++)s2 += to[i];
    // for(int i = 1; i < a; i++)cout << have[i] << " ";
    // cout << endl;
    // for(int i = 1; i <= b; i++)cout << to[i] << " ";
    // cout << endl;
    ans = s1 + s2;
    if(to[b]){
        s2--;
        int v = min(s1/2, s2/2);
        ans -= v * 2;
        s1 -= v*2;
        s2 -= v*2;
        if(s1 && s2){
            ans -= 2;
        }
    }else{
        int v = min(s1/2, s2/2);
        ans -= v * 2;
    }
    cout << ans << endl;
    return 0;
}

Details

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

Test #1:

score: 10
Accepted
time: 0ms
memory: 3636kb

input:

3 3 6
3 1
1 2
2 2
3 3
3 2
1 1

output:

2

result:

ok single line: '2'

Test #2:

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

input:

3 3 6
2 3
1 3
1 1
3 1
2 2
1 2

output:

2

result:

ok single line: '2'

Test #3:

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

input:

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

output:

4

result:

ok single line: '4'

Test #4:

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

input:

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

output:

4

result:

ok single line: '4'

Test #5:

score: 10
Accepted
time: 7ms
memory: 4084kb

input:

114 515 58710
1 1
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 18
1 19
...

output:

114

result:

ok single line: '114'

Test #6:

score: 10
Accepted
time: 9ms
memory: 4092kb

input:

115 515 59225
1 1
1 2
1 3
1 4
1 5
1 6
1 7
1 8
1 9
1 10
1 11
1 12
1 13
1 14
1 15
1 16
1 17
1 18
1 19
...

output:

515

result:

ok single line: '515'

Test #7:

score: 10
Accepted
time: 115ms
memory: 7336kb

input:

68944 65538 457334
28574 3442
25145 16846
3908 4208
1458 23374
6977 13895
15623 10242
5458 32462
147...

output:

16390

result:

ok single line: '16390'

Test #8:

score: 10
Accepted
time: 106ms
memory: 7340kb

input:

80715 54106 456937
6635 12392
6993 23015
16612 416
1154 31247
30337 8910
20012 15283
25326 8635
3175...

output:

16501

result:

ok single line: '16501'

Test #9:

score: 10
Accepted
time: 117ms
memory: 7380kb

input:

54914 55025 464166
7197 327
19912 4344
14147 30464
22874 24904
16761 27174
16591 1399
28037 9082
180...

output:

16416

result:

ok single line: '16416'

Test #10:

score: 10
Accepted
time: 117ms
memory: 7328kb

input:

80584 52252 456351
32761 6996
21358 22163
11514 9134
17800 13069
629 22725
8945 19723
9490 2413
2233...

output:

16395

result:

ok single line: '16395'

Extra Test:

score: 0
Extra Test Passed