QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#181567#5580. Branch Managerwiseman123WA 305ms35660kbC++141.1kb2023-09-16 20:47:482023-09-16 20:47:48

Judging History

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

  • [2023-09-16 20:47:48]
  • 评测
  • 测评结果:WA
  • 用时:305ms
  • 内存:35660kb
  • [2023-09-16 20:47:48]
  • 提交

answer

#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
const int maxn=2e5+10;
using namespace std;
map<pair<int,int>,int> mp;
set<pair<int,int> >v[maxn];
int cnt,n,m,ans;
int out[maxn];
bool vis[maxn],flag;
void dfs(int d,int now,int last)
{ 
     if(flag) return ;
     if(d==now)
     {
        flag=true;
        return ;
     } 
     if(!out[now]&&now!=d)
     {
         vis[mp[{last,now}]]=1;
         return ;
     }
     for(auto u:v[now])
     {
        int ed=u.first,ct=u.second;

        if(vis[ct]) continue;
        else
        {
            if(!flag)
            dfs(d,ed,now);
        }
    } 
}
int main()
{
     cin>>n>>m;
     for(int i=1;i<=n-1;i++)
     {
         int a,b;
         cin>>a>>b;
         v[a].insert({b,++cnt});
         mp[{a,b}]=cnt;
         out[a]++;
     }
     while(m--)
     {
         int ed;
         cin>>ed;
         flag=false;
         dfs(ed,1,0);
         if(!flag) break;
         else ans++;
     }
     cout<<ans;
     return 0;
}

详细

Test #1:

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

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: 0ms
memory: 12916kb

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: 12684kb

input:

2 2
1 2
2
2

output:

2

result:

ok single line: '2'

Test #4:

score: -100
Wrong Answer
time: 305ms
memory: 35660kb

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:

3569

result:

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