Submission #67950212


Source Code Expand

#include <bits/stdc++.h>
#define ll long long
using namespace std;

const ll inf=1e15;
const int Maxn=1010;
int n,m,k,T,Q;
ll f[Maxn][Maxn];

inline void Snc(int x,int y){
	for(int i=1;i<=n+1;i++)
		for(int j=1;j<=n+1;j++)
			f[i][j]=min(f[i][j],f[i][x]+f[x][y]+f[y][j]),
			f[i][j]=min(f[i][j],f[i][y]+f[y][x]+f[x][j]);
}
inline void add(int x){
	f[x][n+1]=min(f[x][n+1],1ll*T); Snc(x,n+1);
	f[n+1][x]=0; Snc(n+1,x);	
}

int main(){
	cin>>n>>m;
	for(int i=1;i<=n+1;i++)
		for(int j=1;j<=n+1;j++)
			f[i][j]=inf;
	for(int i=1;i<=n+1;i++) f[i][i]=0;
	for(int i=1;i<=m;i++){
		int u,v,w;
		cin>>u>>v>>w;
		f[u][v]=f[v][u]=min(f[u][v],1ll*w);
	}
	for(int u=1;u<=n+1;u++)
		for(int i=1;i<=n+1;i++)
			for(int j=1;j<=n+1;j++)
				f[i][j]=min(f[i][j],f[i][u]+f[u][j]);

	cin>>k>>T;
	for(int i=1;i<=k;i++){
		int d; cin>>d;
		add(d);
	}

	cin>>Q;
	while(Q--){
		int opt,x,y,t;
		cin>>opt;
		if(opt==1){
			cin>>x>>y>>t;
			f[x][y]=min(f[x][y],t*1ll);
			f[y][x]=min(f[y][x],t*1ll);
			Snc(x,y);
		}
		if(opt==2){
			cin>>x; add(x);
		}
		if(opt==3){
			ll ans=0;
			for(int i=1;i<=n;i++)
				for(int j=1;j<=n;j++)
					if(f[i][j]!=inf) ans+=f[i][j];
			cout<<ans<<"\n";
		}
	}


	return 0;
}

Submission Info

Submission Time
Task E - Development
User AceTaffy_
Language C++ 20 (gcc 12.2)
Score 450
Code Size 1250 Byte
Status AC
Exec Time 472 ms
Memory 7524 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 450 / 450
Status
AC × 1
AC × 29
Set Name Test Cases
Sample sample_01.txt
All hand.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, sample_01.txt
Case Name Status Exec Time Memory
hand.txt AC 1 ms 3452 KiB
random_01.txt AC 352 ms 7468 KiB
random_02.txt AC 77 ms 5028 KiB
random_03.txt AC 430 ms 7452 KiB
random_04.txt AC 330 ms 6848 KiB
random_05.txt AC 368 ms 7396 KiB
random_06.txt AC 99 ms 5268 KiB
random_07.txt AC 441 ms 7448 KiB
random_08.txt AC 407 ms 7240 KiB
random_09.txt AC 381 ms 7428 KiB
random_10.txt AC 108 ms 5260 KiB
random_11.txt AC 448 ms 7452 KiB
random_12.txt AC 230 ms 6128 KiB
random_13.txt AC 388 ms 7448 KiB
random_14.txt AC 92 ms 5188 KiB
random_15.txt AC 460 ms 7416 KiB
random_16.txt AC 278 ms 6308 KiB
random_17.txt AC 404 ms 7412 KiB
random_18.txt AC 302 ms 6716 KiB
random_19.txt AC 471 ms 7524 KiB
random_20.txt AC 347 ms 6744 KiB
random_21.txt AC 143 ms 5536 KiB
random_22.txt AC 138 ms 5564 KiB
random_23.txt AC 268 ms 5972 KiB
random_24.txt AC 180 ms 5672 KiB
random_25.txt AC 331 ms 7416 KiB
random_26.txt AC 472 ms 7420 KiB
random_27.txt AC 351 ms 7416 KiB
sample_01.txt AC 1 ms 3676 KiB