QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#128184 | #905. 三元环枚举 | myee# | WA | 23ms | 7652kb | C++11 | 2.0kb | 2023-07-20 17:32:44 | 2023-07-20 17:32:45 |
Judging History
answer
// 那就是希望。
// 即便需要取模,也是光明。
#include <algorithm>
#include <queue>
#include <random>
#include <stdio.h>
#include <vector>
typedef long long llt;
typedef unsigned uint;typedef unsigned long long ullt;
typedef bool bol;typedef char chr;typedef void voi;
typedef double dbl;
template<typename T>bol _max(T&a,T b){return(a<b)?a=b,true:false;}
template<typename T>bol _min(T&a,T b){return(b<a)?a=b,true:false;}
template<typename T>T lowbit(T n){return n&-n;}
template<typename T>T gcd(T a,T b){return b?gcd(b,a%b):a;}
template<typename T>T lcm(T a,T b){return(a!=0||b!=0)?a/gcd(a,b)*b:(T)0;}
template<typename T>T exgcd(T a,T b,T&x,T&y){if(b!=0){T ans=exgcd(b,a%b,y,x);y-=a/b*x;return ans;}else return y=0,x=1,a;}
template<typename T>T power(T base,T index,T mod)
{
T ans=1%mod;
while(index)
{
if(index&1)ans=ans*base%mod;
base=base*base%mod,index>>=1;
}
return ans;
}
// Heaven and Earth... My guiding star...
// Akira Complex R.I.P.
const ullt Mod=998244353;
std::vector<uint>Way[100005];
ullt W[100005];
uint P[100005];
int main()
{
#ifdef MYEE
freopen("QAQ.in","r",stdin);
freopen("QAQ.out","w",stdout);
#endif
uint n,m;scanf("%u%u",&n,&m);for(uint i=0;i<n;i++)scanf("%llu",W+i),P[i]=i;
while(m--){uint u,v;scanf("%u%u",&u,&v),Way[u].push_back(v),Way[v].push_back(u);}
std::sort(P,P+n,[&](uint a,uint b){return Way[a].size()<Way[b].size();});
for(uint i=0;i<n;i++)
{
static bol B[100005];
B[P[i]]=true;
std::vector<uint>S;for(auto s:Way[P[i]])if(!B[s])S.push_back(s);
Way[P[i]]=S;
}
ullt ans=0;
for(uint i=0;i<n;i++)
{
static bol B[100005];
for(auto s:Way[P[i]])B[s]=true;
ullt wil=0;
for(auto s:Way[P[i]])
{
ullt r=0;
for(auto t:Way[s])if(B[s])r+=W[t];
if(r)wil=(wil+r%Mod*W[s])%Mod;
}
ans=(ans+wil*W[P[i]])%Mod;
for(auto s:Way[P[i]])B[s]=false;
}
printf("%llu\n",ans);
return 0;
}
// 那就是希望。
// 即便需要取模,也是光明。
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 5540kb
input:
4 5 1 2 3 4 0 3 2 0 2 1 2 3 1 3
output:
36
result:
ok "36"
Test #2:
score: -100
Wrong Answer
time: 23ms
memory: 7652kb
input:
17707 77101 528756313 434883274 318065816 264440383 659789617 608119380 648104885 725454492 696703871 543030428 663661240 890791532 108201616 428505484 322953840 119811886 691103780 306647414 549862302 176916719 909058872 455464665 307270851 584469329 722629343 875317523 629938577 244419357 78121457...
output:
231695503
result:
wrong answer 1st words differ - expected: '397965084', found: '231695503'