QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#449297 | #7790. 最短路求和 | kkkgjyismine4 | 20 | 33ms | 12720kb | C++23 | 1.8kb | 2024-06-20 21:41:57 | 2024-06-20 21:41:57 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
const int inf=1e9;
int n,m;
int id[100005],dg[100005],tot,pos[2050],d[4050],nxtw[2050],ct[100005];
vector<pii>road[100005];
vector<pii>Road[2005];
int dis[2005][2005];
ll Ans;
queue<int>q;
vector<int>vec[3050];
int tt,lf[3050],rg[3050];
void dfs(int u){
pos[++tot]=u,dg[u]=-1;
for(auto v:road[u])if(dg[v.fi]!=-1)dfs(v.fi);
}
int main(){
scanf("%d%d",&n,&m);
for(int i=1;i<=m;++i){
int u,v;ll w;
scanf("%d%d%d",&u,&v,&w);
road[u].pb(mp(v,w)),road[v].pb(mp(u,w));
++dg[u],++dg[v];
}
for(int i=1;i<=n;++i)ct[i]=1;
for(int i=1;i<=n;++i)if(dg[i]==1)q.push(i);
while(!q.empty()){
int u=q.front();q.pop();dg[u]=-1;
int v,w;for(auto v1:road[u])if(dg[v1.fi]>0)v=v1.fi,w=v1.se;
--dg[v];Ans+=1ll*(n-ct[u])*ct[u]*w,ct[v]+=ct[u];
if(!dg[v])cout<<Ans,exit(0);
if(dg[v]==1)q.push(v);
}
for(int i=1;i<=n;++i)if(dg[i]>2)id[i]=++tot,pos[tot]=i;
if(!tot){
int Id=-1;
for(int i=1;i<=n;++i)if(dg[i]>0)Id=i;
dfs(Id);
for(int i=1;i<=tot;++i){
int Nxt=pos[i%tot+1];
for(auto v:road[pos[i]])if(v.fi==Nxt)nxtw[i]=v.se;
}
for(int i=1;i<=tot+1;++i)d[i]=d[i-1]+nxtw[i-1];
int cir=d[tot+1],x=cir/2;
int sct=0,sct1=n;ll sum=0,sum1=0;int now=0;
for(int i=1;i<=n;++i)sum1+=1ll*ct[pos[i]]*d[i];
for(int i=1;i<=tot;++i){
while(now<tot&&d[now+1]-d[i]<=x){++now,sct+=ct[pos[now]],sum+=1ll*ct[pos[now]]*d[now];}
Ans+=1ll*ct[pos[i]]*sum-1ll*ct[pos[i]]*d[i]*sct;
Ans+=-1ll*ct[pos[i]]*(sum1-sum)+1ll*ct[pos[i]]*(d[i]+cir)*(sct1-sct);
sct-=ct[pos[i]],sct1-=ct[pos[i]];
sum-=1ll*ct[pos[i]]*d[i],sum1-=1ll*ct[pos[i]]*d[i];
}
cout<<Ans,exit(0);
}
cout<<Ans;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3816kb
input:
300 1300 90 125 9397 157 77 3704 197 112 8218 152 235 1702 271 107 5600 117 92 1401 104 61 2242 127 230 1471 91 116 2740 29 127 4326 151 78 2569 273 241 7487 170 115 3100 152 171 2504 193 95 5921 30 281 1309 285 262 6462 100 265 8151 200 90 277 237 151 1123 231 219 974 238 176 2239 89 147 2256 233 2...
output:
0
result:
wrong answer 1st lines differ - expected: '324731073', found: '0'
Subtask #2:
score: 10
Accepted
Test #5:
score: 10
Accepted
time: 29ms
memory: 9900kb
input:
100000 99999 54625 54626 7146 20763 20764 300 41530 41531 9968 37448 37449 7434 81056 81055 700 27731 27730 8783 12408 12409 514 90652 90653 99 84104 84105 2524 83093 83094 195 17757 17756 2560 81925 81926 8935 14220 14219 9619 25516 25515 5883 89413 89412 275 46936 46937 3997 82755 82754 2775 53080...
output:
834269687204155387
result:
ok single line: '834269687204155387'
Test #6:
score: 0
Accepted
time: 33ms
memory: 10580kb
input:
100000 99999 13706 21290 3420 3037 78334 3887 94743 35121 9291 67873 91038 345 48348 12825 56 25237 56325 19 44215 92806 6788 40110 98929 5038 43250 87034 907 19698 18774 44 79406 51075 9523 79992 15613 4062 91111 66707 1595 1223 12300 3924 65613 22546 9008 24856 20394 393 14915 86273 5876 39594 160...
output:
4573680940298584
result:
ok single line: '4573680940298584'
Subtask #3:
score: 10
Accepted
Test #7:
score: 10
Accepted
time: 29ms
memory: 12720kb
input:
100000 100000 35241 48789 5098 4546 39869 6127 31415 22834 6026 25703 1952 6807 86143 78951 3421 34193 9615 4329 31012 98959 1664 81244 37874 3542 600 74315 9939 91066 57088 2111 5064 33313 9799 78834 28718 1133 41687 82171 4214 44801 87500 4238 40150 73606 5172 17787 30281 3718 52715 82529 4419 924...
output:
3317259529562659
result:
ok single line: '3317259529562659'
Test #8:
score: 0
Accepted
time: 33ms
memory: 10672kb
input:
100000 100000 45035 91419 579 57950 84820 2866 89160 29146 2750 87309 96239 135 1932 78121 5243 72536 91944 8466 89557 37259 9516 26079 66778 2699 63510 69399 8539 77547 58834 2244 53857 24982 5272 81809 33349 6648 78486 82374 4634 4290 81980 2143 4305 91524 4722 99911 87695 1124 91290 10670 2828 24...
output:
3401469393921409
result:
ok single line: '3401469393921409'
Subtask #4:
score: 0
Wrong Answer
Dependency #2:
100%
Accepted
Dependency #3:
100%
Accepted
Test #9:
score: 0
Wrong Answer
time: 32ms
memory: 10704kb
input:
100000 100020 80942 35082 1070 97375 16208 4147 33462 96122 7583 83987 22763 1859 69816 43966 8458 91076 6312 1456 48229 88568 1216 5646 80520 5669 630 34701 3490 79455 92863 4483 82919 50914 4411 90738 90713 4038 78668 71114 3542 29889 64989 400 32720 8892 7829 34321 83166 8197 34269 51783 4880 424...
output:
1044720143262310
result:
wrong answer 1st lines differ - expected: '2809946608338124', found: '1044720143262310'
Subtask #5:
score: 0
Skipped
Dependency #4:
0%
Subtask #6:
score: 0
Skipped
Dependency #1:
0%