QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#96591 | #5591. Fading Wind | PetroTarnavskyi# | WA | 1ms | 9192kb | C++17 | 1.1kb | 2023-04-14 16:37:54 | 2023-04-14 16:37:56 |
Judging History
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;
}
詳細信息
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'