QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#150431 | #5580. Branch Manager | value0 | WA | 59ms | 23448kb | C++20 | 1.3kb | 2023-08-25 17:07:44 | 2023-08-25 17:07:45 |
Judging History
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];
}
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;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 13568kb
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: 4ms
memory: 13024kb
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: 13996kb
input:
2 2 1 2 2 2
output:
2
result:
ok single line: '2'
Test #4:
score: -100
Wrong Answer
time: 59ms
memory: 23448kb
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'