QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#19948#2289. Jail or JoyrideRealityang#WA 2ms3912kbC++142.0kb2022-02-14 12:52:212022-05-08 01:40:19

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-05-08 01:40:19]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3912kb
  • [2022-02-14 12:52:21]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
int num,vi[310],lj[310][310],an,di[310],d[310][310];
int d2[310],ddd,d1[310][310],n,m,s,t,dd[310],ru[310],dis[310],vis[310];
queue<int>q;
void ed(){printf("impossible");exit(0);}
void bfs(int ss,int bd1,int bd2){
	q.push(ss);
	for(int i=1;i<=n;i++)vi[i]=0;vi[ss]=1;
	while(!q.empty()){
		int x=q.front();q.pop();
		for(int i=1;i<=n;i++){
			if(!vi[i]&&lj[i][x]){
				if((x==bd1&&i==bd2)||(i==bd1&&x==bd2))continue;
				if(!vi[i])vi[i]=1,q.push(i);
			}
		}
	}
}
signed main(){
	scanf("%lld%lld%lld%lld",&n,&m,&s,&t);
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++)d[i][j]=d1[i][j]=1e18;
		d[i][i]=d1[i][i]=0;
	}
	for(int i=1,u,v,w;i<=m;i++){
		scanf("%lld%lld%lld",&u,&v,&w);
		d[u][v]=d[v][u]=d1[u][v]=d1[v][u]=w;ru[u]++;ru[v]++;
		lj[u][v]=lj[v][u]=1;
	}
	for(int k=1;k<=n;k++){
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++){
				d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
			}
		}
	}
	if(d[s][t]==1e18)ed();
	for(int i=1;i<=n;i++)for(int j=1;j<=n;j++)if(i!=j)di[i]=max(di[i],d[i][j]);
	do{
		num=0;
		for(int i=1;i<=n;i++){
			if(vis[i])continue;
			int fl=1;
			if(ru[i]==1){vis[i]=1;num++;continue;}
			for(int j=1;j<=n;j++)if(i!=j&&di[i]==d[i][j]){
				if(!vis[j])fl=0;
			}num+=fl;
			if(fl){vis[i]=1;
				for(int j=1;j<=n;j++)if(i!=j&&di[i]==d[i][j]&&vis[j])dis[i]=max(dis[i],dis[j]+d[i][j]);
			}
		}
	}while(num);
	for(int k=1;k<=n;k++){
		if(k==t)continue;
		for(int i=1;i<=n;i++){
			if(i==t)continue;
			for(int j=1;j<=n;j++){
				if(j==t)continue;
				d1[i][j]=min(d1[i][j],d1[i][k]+d1[k][j]);
			}
		}
	}int fl=1;
	for(int i=1;i<=n;i++){
		if(lj[i][t]&&d1[s][i]!=1e18){
			bfs(t,t,i);di[t]=0;
			for(int j=1;j<=n;j++)if(vi[j])di[t]=max(di[t],d[t][j]);
			for(int j=1;j<=n;j++){
				if(i==j)continue;
				if(d[t][j]==di[t]&&vi[j]){
					if(!vis[j])fl=0;
					else an=max(an,d[s][i]+d[i][t]+d[t][j]+dis[j]);
				}
			}
		}
	}
	if(fl)printf("%lld",an);
	else ed();
}
/*
4 3 1 3
1 2 1
2 3 2
3 4 2
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

9 10 1 2
1 2 225869
2 3 1772
3 4 314393
4 5 692250
5 6 684107
4 6 532792
3 7 441133
7 8 468183
8 9 186297
7 9 228792

output:

impossible

result:

ok single line: 'impossible'

Test #2:

score: 0
Accepted
time: 1ms
memory: 3912kb

input:

9 10 3 2
1 2 225869
2 3 1772
3 4 314393
4 5 692250
5 6 684107
4 6 532792
3 7 441133
7 8 468183
8 9 186297
7 9 228792

output:

227641

result:

ok single line: '227641'

Test #3:

score: -100
Wrong Answer
time: 2ms
memory: 3912kb

input:

8 22 8 1
1 2 11
1 3 11
1 4 11
1 5 11
1 6 11
1 7 10
2 3 12
2 4 12
2 5 12
2 6 12
2 7 11
3 4 13
3 5 13
3 6 13
3 7 12
4 5 14
4 6 14
4 7 13
5 6 15
5 7 14
6 7 15
7 8 1

output:

108

result:

wrong answer 1st lines differ - expected: '92', found: '108'