QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#739477#2272. Formica Sokobanicak1nsomWA 28ms18808kbC++141.5kb2024-11-12 21:52:422024-11-12 21:52:43

Judging History

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

  • [2024-11-12 21:52:43]
  • 评测
  • 测评结果:WA
  • 用时:28ms
  • 内存:18808kb
  • [2024-11-12 21:52:42]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
#define int long long
#define endl '\n'
#define PII pair<int, int>
const int N = 2e5 + 5;
int n, m, ans, vis[N], mx[N];
vector<int> e[N];
void dfs(int u, int fa, int ok)
{
    if (ok && vis[u])
    {
        return;
    }
    ans++;
    if (vis[u])
    {
        int cnt = 0;
        for (auto to : e[u])
            if (to != fa && !vis[to])
                cnt++;
        int mx = 0;
        if (cnt >= 2)
            mx = 1;
        for (auto to : e[u])
            if (to != fa)
            {
                dfs(to, u, ok + 1 - mx);
            }
    }
    else
    {

        int cnt = 0;
        for (auto to : e[u])
            if (to != fa && !vis[to])
                cnt++;
        int mx = 0;
        if (cnt >= 2)
            mx = 1;
        for (auto to : e[u])
            if (to != fa)
                dfs(to, u, max(0ll, ok - mx));
    }
    if (u != 1 && e[u].size() == 1 && ok)
        ans--;
}

void solve()
{
    cin >> n >> m;
    for (int i = 1; i < n; i++)
    {
        int u, v;
        cin >> u >> v;
        e[u].push_back(v);
        e[v].push_back(u);
    }
    for (int i = 1; i <= m; i++)
    {
        int x;
        cin >> x;
        vis[x] = 1;
    }
    dfs(1, 0, 0);
    cout << ans << endl;
}

signed main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t = 1;
    while (t--)
        solve();
    return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 28ms
memory: 18808kb

input:

200000 67431
1 134415
1 3
1 4
11 1
13 1
19 1
1 25
31 1
1 33
41 1
46 1
48 1
1 52
1 55
60 1
63 1
1 77
78 1
85 1
1 86
1 87
90 1
92 1
95 1
1 96
1 98
1 103
1 115
1 123
1 126
1 128
1 130
137 1
140 1
141 1
1 142
153 1
162 1
165 1
167 1
1 169
1 170
177 1
1 187
1 189
1 190
1 193
1 197
202 1
1 216
1 220
1 222...

output:

200000

result:

wrong answer 1st lines differ - expected: '132569', found: '200000'