QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#249908#6623. Perfect Matchingsucup-team1001#TL 0ms3456kbC++231.8kb2023-11-12 17:49:582023-11-12 17:49:59

Judging History

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

  • [2023-11-12 17:49:59]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3456kb
  • [2023-11-12 17:49:58]
  • 提交

answer

#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ull = unsigned long long;

#define IOS ios::sync_with_stdio(0);cin.tie(0);
#define endl "\n"
#define int ll

void solve() {
//    int n;
//    cin >> n;

    int n, t;
    cin >> n;
    vector<vector<int>> v(2*n + 10, vector<int>(2*n + 10, 1));
    for (int i = 1; i < 2 * n; i++) {
        int x, y;
        cin >> x >> y;
        v[x][y] = 0;
        v[y][x] = 0;
    }
    vector<int> ans;
    ans.push_back(1);
    vector<int> vis(n + 10, 1);
    vis[1] = 0;
    int ans1 = 0;
    function<void(int, int, int)> dfs = [&](int pre, int k, int is) {
        if (k == n) {
//         10
            ans1++;
            return;
        }
        if (is == 1) {
            for (int i = pre + 1; i <= n * 2; i++) {
                if (vis[i]) {
                    if (v[pre][i]) {
                        vis[i] = 0;
                        ans.push_back(i);
                        dfs(i, k + 1, 0);
                        ans.erase(--ans.end());
                        vis[i] = 1;
                    }
                }
            }
        } else {
            for (int i = 2; i <= n * 2; i++) {
                if (vis[i]) {
                    vis[i] = 0;
                    ans.push_back(i);
                    dfs(i, k, 1);
                    ans.erase(--ans.end());
                    vis[i] = 1;
                    return;
                }

            }
        }
    };

    dfs(1, 0, 1);
    cout << ans1 << endl;
}


signed main() {
//    IOS
    int t = 1;
//    cin >> t;
    while (t--)solve();
}
//10000
//3 0
//3 1
//1 2
//3 2
//1 2 2 3
//3 3
//1 2 2 3 3 4
//3 3
//1 2 1 3 1 4
// 3 4
// 1 2 2 3 3 4 4 5
//3 5
//1 2 2 3 1 4 4  5 4 6
//3 5
//1 2 2 3 3 4 4 5 4 6

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
1 2
1 3
3 4

output:

1

result:

ok 1 number(s): "1"

Test #2:

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

input:

3
1 2
2 3
3 4
4 5
5 6

output:

5

result:

ok 1 number(s): "5"

Test #3:

score: -100
Time Limit Exceeded

input:

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

output:


result: