QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#150639 | #5580. Branch Manager | value0 | WA | 50ms | 24100kb | C++20 | 1.3kb | 2023-08-25 22:45:49 | 2023-08-25 22:45:49 |
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 dfs(int u)
{
st[u] = 1;
if(e[u].empty())
{
return;
}
dfs(*e[u].begin());
}
void del(int u)
{
st[u] = 2;
for(auto v : e[u])
{
del(v);
}
}
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;
}
dfs(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];
}
// cout<<"u :"<<u<<endl;
del(*e[u].begin());
e[u].erase(*e[u].begin());
for(auto &v : e[u])
{
if(st[v] == 1)
{
if(v == t)
{
dfs(v);
break;
}
u = v;
}
else
{
del(v);
e[u].erase(v);
}
}
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: 0ms
memory: 13184kb
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: 13652kb
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: 3ms
memory: 14008kb
input:
2 2 1 2 2 2
output:
2
result:
ok single line: '2'
Test #4:
score: -100
Wrong Answer
time: 50ms
memory: 24100kb
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:
8
result:
wrong answer 1st lines differ - expected: '3563', found: '8'