题意很简单,直接暴力就可以做了。先dfs把图转化为有根树(记录父亲节点)然后暴力。下面直接贴代码(第一次做出E题,很激动有没有)
#include <set>
#include <map>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <cctype>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
const int inf = 0x3f3f3f3f;
const double eps = 1e-8;
const int maxn = 1e5+10;
int pa[maxn],tree[maxn];
int n,q;
struct
{
int to,next;
} e[2*maxn];
int head[maxn],tot,cnt;
bool vis[maxn];
int gcd(i