#1964. 珅泽教育CSP-J第一轮模拟考第十二套 第 43 题

珅泽教育CSP-J第一轮模拟考第十二套 第 43 题

第2题

给定 NN 个点、MM 条边,构成一个图。请统计从 11 号出发,有多少条简单路径。所谓简单路径,就是路径上的所有点及所有边不会重复出现两次。如果路径超过 10241024 条,则输出 1-1

#include <iostream>
#include <vector>

int N, M;
std::vector<int> adj[200001]; // 邻接表
bool visited[200001];
const int limit = 1024;
int cnt = 0;

void dfs(int node)
{
    ____(1)____;
    if (cnt > limit) return;
    visited[node] = ____(2)____;
    for (auto v : ____(3)____)
    {
        if (not visited[v])
        {
            dfs(____(4)____);
        }
    }
    visited[node] = ____(5)____;
}

int main()
{
    std::cin >> N >> M;
    for (int i = 0; i < M; ++i) {
        int A, B;
        std::cin >> A >> B;
        adj[A].push_back(B);
        adj[B].push_back(A);
    }
    dfs(____(6)____);
    if (cnt > limit) {
        std::cout << -1 << "\n";
    }
    else {
        std::cout << cnt << "\n";
    }
}

11)处应填( )。

{{ select(1) }}

  • cnt += 1
  • cnt -= 1
  • cnt *= 2
  • cnt += 2