QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#181564#5580. Branch Manageryyc4591WA 0ms3824kbC++14751b2023-09-16 20:45:292023-09-16 20:45:29

Judging History

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

  • [2023-09-16 20:45:29]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3824kb
  • [2023-09-16 20:45:29]
  • 提交

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;
}

Details

Tip: Click on the bar to expand more detailed information

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'