题意:
给你n个点的地图,这个地图由n-1条边链接,那肯定是树了,然后给你m个起点,问你从这m个起点出发到达1,路上消灭的叛军数量。
题解:
直接从1深搜,跑一边地图,回溯时,如果出现起点,那么之前的叛军全部消灭。
值得注意的是 vector的速度在这道题远远大于链式前向星。
以后慎用vector。。。
#include<string>
#include<vector>
#include<queue>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<set>
#define ll long long
#define x first
#define y second
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
const int mod=11;
const int maxn=1e5+100;
int n,m,cnt;
ll ans;
int cost[maxn];
bool vis[maxn],book[maxn];
int head[maxn];
struct node{
int to,nxt;
}e[maxn*2];
void addedge(int u,int v){
e[++