跳到正文

题解

T546526 吃鸡之旅 题解

__bilibili_daogu__约 1 分钟
原文
文章信息与版本

文章信息

发布
2025年1月24日
收录
2025年12月12日
更新
2026年11月22日
篇幅
约 1 分钟

版本

  1. v1当前

c++:

C++
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

const int MAXN = 100005;

int n, m, k;
int a[MAXN], h[MAXN];
vector<int> adj[MAXN];
bool visited[MAXN];

int dfs(int u) {
    visited[u] = true;
    int ans = 0;
    if (k > a[u] * h[u]) {
        ans += a[u];
        for (int v : adj[u]) {
            if (!visited[v]) {
                ans += dfs(v);
            }
        }
    }
    return ans;
}

int main() {
    cin >> n >> m >> k;
    for (int i = 1; i <= m; i++) {
        int u, v;
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    for (int i = 1; i <= n; i++) {
        cin >> a[i] >> h[i];
    }
    cout << dfs(1) << endl;
    return 0;
}


原文