QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#96591#5591. Fading WindPetroTarnavskyi#WA 1ms9192kbC++171.1kb2023-04-14 16:37:542023-04-14 16:37:56

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-04-14 16:37:56]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:9192kb
  • [2023-04-14 16:37:54]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define FOR(i, a, b) for (int i = (a); i<(b); ++i)
#define RFOR(i, b, a) for (int i = (b)-1; i>=(a); --i)
#define MP make_pair
#define PB push_back
#define F first
#define S second

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;

const int N = 200447;
VI g[N];
int tin[N];
int tout[N];
int T;

void dfs(int v)
{
	tin[v] = T++;
	for (auto u : g[v])
		dfs(u);
	tout[v] = T;
}

bool is_par(int p, int v)
{
	return tin[p] < tin[v] && tout[v] <= tout[p];
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n, m;
	cin >> n >> m;
	FOR(i, 0, n - 1)
	{
		int a, b;
		cin >> a >> b;
		a--, b--;
		g[a].PB(b);
	}
	FOR(i, 0, n) sort(ALL(g[i]));
	dfs(0);
	int ans = 1;
	int ls;
	cin >> ls;
	ls--;
	FOR(i, 0, m - 1)
	{
		int x;
		cin >> x;
		x--;
		if (tin[x] >= tin[ls] || is_par(x, ls))
		{
			ls = x;
			ans++;
		}
		else
		{
			break;
		}
	}
	cout << ans << '\n';
	
	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

1 1 1 1

output:

1

result:

ok single line: '1'

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 9044kb

input:

2 2 2 2

output:

2

result:

wrong answer 1st lines differ - expected: '9', found: '2'