QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#19862#2289. Jail or JoyrideRealityang#WA 1ms3820kbC++141.2kb2022-02-12 15:20:022022-05-06 07:22:39

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-06 07:22:39]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3820kb
  • [2022-02-12 15:20:02]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
int num,di[310],d[310][310],n,m,s,t,dd[310],ru[310],dis[310],vis[310],lj[310][310];
void ed(){printf("impossible");exit(0);}
void dfs(int u){
	if(vis[u])ed();
	for(int i=1;i<=n;i++){
		if(i==u||!lj[i][u])continue;
		vis[i]=1;
		dd[i]=dd[u]+d[i][u];
		dfs(i);
		vis[i]=0;
	}
}
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]=1e9;
		d[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]=w;ru[u]++;ru[v]++;
	}
	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]==1e9)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;
				else dis[i]=max(dis[i],dis[j]+d[i][j]);
			}
			num+=fl;if(fl)vis[i]=1;
		}
	}while(num);
	if(vis[t])printf("%lld",dis[t]+d[s][t]);
	else ed();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3692kb

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: -100
Wrong Answer
time: 1ms
memory: 3820kb

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:

impossible

result:

wrong answer 1st lines differ - expected: '227641', found: 'impossible'