QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#249907#6623. Perfect Matchingsucup-team1001#RE 1ms3408kbC++231.8kb2023-11-12 17:49:272023-11-12 17:49:28

Judging History

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

  • [2023-11-12 17:49:28]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:3408kb
  • [2023-11-12 17:49:27]
  • 提交

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(n + 10, vector<int>(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

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3408kb

input:

2
1 2
1 3
3 4

output:

1

result:

ok 1 number(s): "1"

Test #2:

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

input:

3
1 2
2 3
3 4
4 5
5 6

output:

5

result:

ok 1 number(s): "5"

Test #3:

score: -100
Runtime Error

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: