QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#449295#7790. 最短路求和kkkgjyismine40 23ms10704kbC++231.8kb2024-06-20 21:38:582024-06-20 21:38:58

Judging History

This is the latest submission verdict.

  • [2024-06-20 21:38:58]
  • Judged
  • Verdict: 0
  • Time: 23ms
  • Memory: 10704kb
  • [2024-06-20 21:38:58]
  • Submitted

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*ct[v]*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;
}

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3692kb

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: 0
Wrong Answer

Test #5:

score: 0
Wrong Answer
time: 18ms
memory: 9932kb

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:

15683352397031

result:

wrong answer 1st lines differ - expected: '834269687204155387', found: '15683352397031'

Subtask #3:

score: 0
Wrong Answer

Test #7:

score: 0
Wrong Answer
time: 23ms
memory: 10704kb

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:

486689158527612

result:

wrong answer 1st lines differ - expected: '3317259529562659', found: '486689158527612'

Subtask #4:

score: 0
Skipped

Dependency #2:

0%

Subtask #5:

score: 0
Skipped

Dependency #4:

0%

Subtask #6:

score: 0
Skipped

Dependency #1:

0%