做完之后感觉 这个题应该是需要一些数学思想
题解看这个博客:代码如下
#include#include #include using namespace std; #define in = read(); typedef long long ll; typedef unsigned int ui; const ll size = 1000000 + 10000; struct point{ ll next,to,dis;}edge[size]; ui n; ui a[size]; ui site,ans,maxans; ui head[size];inline ll read(){ ll num = 0 , f = 1; char ch = getchar(); while(!isdigit(ch)){ if(ch == '-') f = -1; ch = getchar(); } while(isdigit(ch)){ num = num*10 + ch - '0'; ch = getchar(); } return num*f;}inline void add(ll x,ll y){ edge[++site].next = head[x]; edge[site].to = y; head[x] = site;}int main(){ n in; for(int i=1;i max1){ max2 = max1; max1 = a[edge[j].to]; } else if(a[edge[j].to] > max2) max2 = a[edge[j].to]; ans = (ans + sum*a[edge[j].to])%10007; sum = (sum + a[edge[j].to])%10007; maxans = max(maxans , max1*max2); } } ans = (ans*2)%10007; printf("%d %d",maxans,ans);}//COYG