QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#181564 | #5580. Branch Manager | yyc4591 | WA | 0ms | 3824kb | C++14 | 751b | 2023-09-16 20:45:29 | 2023-09-16 20:45:29 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int n, m;
cin >> n >> m;
vector<int>adj[n + 1];
for (int i = 0, u, v; i < n - 1; i ++) {
cin >> u >> v;
adj[u].push_back(v);
}
queue<int>q;
for (int i = 0, d; i < m; i++) {
cin >> d;
q.push(d);
}
for (int i = 1; i <= n; i++)
sort(adj[i].begin(), adj[i].end());
int ans = 0;
function<void(int)> dfs =[&] (int u)
{
// cout << u << " " << q.front() << endl;
if(u == q.front()) {
q.pop();
ans++;
}
for (auto it : adj[u]) {
dfs(it);
if(u == q.front()) {
q.pop();
ans++;
}
}
};
dfs(1);
cout << ans << endl;
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3748kb
input:
8 5 1 2 4 8 4 6 1 4 2 5 4 7 2 3 5 2 6 4 8
output:
5
result:
ok single line: '5'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3548kb
input:
4 4 1 2 1 3 1 4 3 2 3 4
output:
1
result:
ok single line: '1'
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3824kb
input:
2 2 1 2 2 2
output:
1
result:
wrong answer 1st lines differ - expected: '2', found: '1'