QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#112446#6523. Escape Planxcc_szyAC ✓2563ms84476kbC++233.6kb2023-06-11 19:16:312023-06-11 19:16:33

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-11 19:16:33]
  • 评测
  • 测评结果:AC
  • 用时:2563ms
  • 内存:84476kb
  • [2023-06-11 19:16:31]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int kmaxn=1e5+10,check=1e14;
struct node{
	int ans=1e14,ys=1e14,anp=0,io=0;
	vector<int>to,lp;
	int pi=0;
}a[kmaxn];
int n,m,T,ans[kmaxn];
bool pd[kmaxn],ps[kmaxn];
int ilp[kmaxn];
priority_queue<pair<int,int> >P;
void Clean(){
	memset(pd,0,sizeof(pd));
	P=priority_queue<pair<int,int> >();
}
void Kill(int x){
  if(ps[x]){
    return ;
  }
  ps[x]=1;
  for(int i=0;i<a[x].to.size();i++){
    Kill(a[x].to[i]);
  }
}
int ur[kmaxn];
void CleanMax(){
	memset(pd,0,sizeof(pd));
	P=priority_queue<pair<int,int> >();
	for(int i=1;i<=n;i++){
		pd[i]=0;
		a[i].ans=check;
		a[i].ys=check;
		a[i].anp=0;
		a[i].io=0;
		ilp[i]=i;
		a[i].lp.clear();
		a[i].to.clear();
	}
}
bool Sort(int x,int y){
	if(a[x].io!=a[y].io)return a[x].io<a[y].io;
	if(a[x].pi!=a[y].pi)return a[x].pi<a[y].pi;
	return a[x].anp<a[y].anp;
}
void Add(int s,int t,int lp){
	a[s].lp.push_back(lp);
	a[s].to.push_back(t);
	a[t].lp.push_back(lp);
	a[t].to.push_back(s);
	return ;
}
int E,Et[kmaxn]; 
void Cin(){
	cin>>n>>m>>E;
	CleanMax();
	for(int i=1;i<=E;i++){
		int x;
		cin>>x;
		Et[i]=x;
		P.push({0,x});
	}
	for(int j=1;j<=n;j++){
		cin>>ur[j];
	}
	for(int i=1;i<=E;i++){
		ur[Et[i]]=0;
	}
	for(int i=1;i<=m;i++){
		int s,t,lp;
		cin>>s>>t>>lp;
		Add(s,t,lp);
	}
	return ;
}
void Dijout(int x){
	int an=0;
	for(int i=1;i<=n;i++){
		an+=i*a[i].ans;
	}
	ans[x]=an;
	return ;
}
bool PDout(int x){
	bool pg=0;
	for(int i=1;i<=n;i++){
		for(int j=0;j<a[i].to.size();j++){
			if(a[i].ans+a[i].lp[j]<a[a[i].to[j]].ans&&a[i].ans!=check){
				//cout<<"No";
				pg=1;
				Kill(i);
			}
		}
	}
	if(pg)return 0;
	Dijout(x);
	return 1;
}
void Dij(int x){
	for(int Above=1;Above<=m*2;Above++){
		while(P.size()&&pd[P.top().second])P.pop();
		if(P.size()==0)return ;
		int x=P.top().second;
		int i=x;
		ur[x]--;
		if(ur[x]>=0){
			P.pop();
			continue;
		}
		pd[x]=1;
		a[x].ans=P.top().first*-1;
		P.pop();
		for(int j=0;j<a[x].to.size();j++){
			if(a[a[i].to[j]].io>0&&(a[i].ys+a[i].lp[j]<a[a[i].to[j]].ys)){
				a[a[i].to[j]].io--;
			}
			if(a[a[i].to[j]].io>0)continue;
			if(a[i].ans+a[i].lp[j]==a[a[i].to[j]].ans&&a[i].anp+1<a[a[i].to[j]].anp&&pd[a[i].to[j]]==0){
				a[a[i].to[j]].anp=a[i].anp+1;
				P.push({a[a[i].to[j]].ans*-1,a[i].to[j]});
			}
			if(a[i].ans+a[i].lp[j]<a[a[i].to[j]].ans&&pd[a[i].to[j]]==0){
				a[a[i].to[j]].anp=a[i].anp+1;
				P.push({(a[i].ans+a[i].lp[j])*-1,a[i].to[j]});
			}
		}
	}
}
void Main(){
	Cin();
	for(int S=1;S<=1;S++){
		Dij(S);
//		if(S==1){
//			for(int i=1;i<=n;i++){
//				cout<<a[i].ans<<" ";
//			}
//			cout<<endl;
//		}
		for(int Above=1;Above<=15;Above++){
			bool pl=0;
			for(int i=1;i<=n;i++)a[i].io=0,a[i].pi=0;
			for(int i=1;i<=n;i++){
				for(int j=0;j<a[i].to.size();j++){
					if(a[i].ans+a[i].lp[j]<a[a[i].to[j]].ans&&a[i].ans!=check){
						a[a[i].to[j]].io++;
						pl=1;
						a[i].pi++;
//						cout<<"No:"<<i<<"->"<<a[i].to[j]<<endl;
					}
				}
			}
			if(pl==0){
				break;
			}
			for(int i=1;i<=n;i++){
				a[i].ys=a[i].ans;
			}
			Clean();
			sort(ilp+1,ilp+1+n,Sort);
			for(int E=1;E<=n;E++){
				int i=ilp[E];
				bool po=0;
				for(int j=0;j<a[i].to.size();j++){
					if(a[i].ans+a[i].lp[j]<a[a[i].to[j]].ans&&a[i].ans!=check){
						po=1;
					}
				}
				if(po)Dij(i);
			}
//			if(S==1){
//				for(int i=1;i<=n;i++){
//					cout<<a[i].ans<<" ";
//				}
//				cout<<endl;
//			}
		}
		if(!PDout(S))return ;
	}
}
int TTT;
signed main(){
	cin>>TTT;
	while(TTT--){
		Main();
		cout<<(a[1].ans==check?-1:a[1].ans)<<endl;
	}
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 2ms
memory: 14612kb

input:

2
3 4 1
3
1 1 1
1 2 1
1 2 2
2 3 1
2 3 2
3 2 2
2 3
2 0 0
1 2 1
1 3 1

output:

4
-1

result:

ok 2 number(s): "4 -1"

Test #2:

score: 0
Accepted
time: 2563ms
memory: 84476kb

input:

100
100 1808 2
94 47
3 3 0 2 4 3 3 4 0 0 2 2 2 3 2 4 0 2 3 4 4 2 0 3 4 3 1 0 2 1 2 2 0 3 4 4 4 1 2 2 3 1 0 0 3 1 4 2 1 3 3 4 3 0 4 1 0 3 2 1 4 4 1 3 2 3 3 3 3 1 0 3 0 4 3 1 0 4 0 4 4 1 2 0 0 4 1 3 3 3 0 2 2 1 1 2 3 4 1 2
72 29 1138
59 78 2398
95 5 1610
32 46 4176
36 99 8143
100 69 413
61 58 1595
9 9...

output:

5109
1021
3293
4646
3796
3394
1884
6772
2329
2067
3296
2809
865
4249
2241
3792
2135
2544
3343
1775
10602
4677
1700
2150
7071
14055
3368
2322
1113
1980
3067
1617
1702
-1
2879
6265
2065
2810
2289
3001
402
3769
18118
6874
7879
3823
-1
510
2636
10564
-1
3166
3615
7526
5549
1261
3302
270
4440
1998
3350
3...

result:

ok 100 numbers