QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#150457#5580. Branch Managervalue0WA 56ms23104kbC++201.4kb2023-08-25 17:28:312023-08-25 17:28:32

Judging History

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

  • [2023-08-25 17:28:32]
  • 评测
  • 测评结果:WA
  • 用时:56ms
  • 内存:23104kb
  • [2023-08-25 17:28:31]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
const int mod = 1e9 + 7;
using ll = long long;
typedef pair<int,int> pii;
int n,m,k;
set<int> e[N];
int p[N];
int st[N];

void add(int u)
{
	st[u] = 1;
	if(e[u].empty())
	{
		return;
	}
	add(*e[u].begin());
}



void del(int u)
{
	st[u] = 2;
	if(e[u].empty())
	{
		return;
	}
	del(*e[u].begin());
}


void solve()
{
	cin>>n>>m;
	for(int i = 1;i < n;i++)
	{
		int a,b;
		scanf("%d %d",&a,&b);
		e[a].insert(b);
		p[b] = a;
	}
	add(1);
	int cnt = 0;
	while(m--)
	{
		int t;
		scanf("%d",&t);
//		cout<<t<<' '<<st[t]<<endl;
		if(st[t] == 2)
		{
			break;
		}	
		if(st[t] == 1)
		{
			cnt ++;
		}
		else
		{
			int u = t;
			while(st[u] == 0)
			{
				st[u] = 1;
				u = p[u];
			}
			if(st[u] == 2)
			{
				break;
			}
			st[*e[u].begin()] = 2;
			del(*e[u].begin());
			e[u].erase(e[u].begin());
			for(auto v : e[u])
			{
				if(st[v] == 1)
				{
					add(v);
					break;
				}
				else
				{
					del(v);
				}
			}
			if(st[u] == 1)
			{
				cnt++;
			}
//			cout<<t<<' '<<st[t]<<endl;
		}
//		for(int i= 1;i<=n;i++)
//		{
//			cout<<i<<' '<<st[i]<<endl;
//		}
//		cout<<endl;
//		puts("YES");
	}
	
	cout<<cnt<<endl;
}

int main()
{
	int t = 1;
//	scanf("%d",&t);
	while(t--)
	{
		solve();
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 13668kb

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: 1ms
memory: 13860kb

input:

4 4
1 2
1 3
1 4
3
2
3
4

output:

1

result:

ok single line: '1'

Test #3:

score: 0
Accepted
time: 4ms
memory: 12896kb

input:

2 2
1 2
2
2

output:

2

result:

ok single line: '2'

Test #4:

score: -100
Wrong Answer
time: 56ms
memory: 23104kb

input:

200000 200000
161672 172858
146306 146322
61159 61510
140802 145171
194221 195447
73888 80278
77016 77115
1382 1417
186221 195091
78442 78451
171750 172141
147707 151432
182664 182798
143183 147414
156646 162546
6630 6706
18452 18519
99764 99811
153419 153707
125659 129068
179317 185954
13947 14278
...

output:

124

result:

wrong answer 1st lines differ - expected: '3563', found: '124'