QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#514922#2272. Formica SokobanicaAfterlife#RE 0ms0kbC++201.1kb2024-08-11 13:31:292024-08-11 13:31:29

Judging History

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

  • [2024-08-11 13:31:29]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-08-11 13:31:29]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
int n , m;
vector<int> E[100005];
int a[100005];
int ans = 0;
void dfs(int fa,int u,int p) {
    p |= a[u];
    // printf("on %d %d\n",u,p);
    if(p == 0) {
        ans++ ;
        for(auto v : E[u]) {
            if(v != fa) dfs(u , v , 0);
        }
    }
    else {
        int tc = -1;
        for(auto v:E[u]) {
            if(v != fa && !a[v]) {
                if(tc == -1)
                    tc = v;
                else tc = -2;
            }
        }
        if(tc == -1) return;
        ans++ ;
        for(auto v : E[u]) {
            if(v != fa) {
                if(v == tc) dfs(u , v , 1);
                else dfs(u , v , 0);
            }
        }
    }
}
int main() {
    ios::sync_with_stdio(false) ; cin.tie(0) ;
    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;a[x] = 1;
    }
    dfs(0 , 1 , 0);
    cout << ans << '\n';
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

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:


result: