QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#19863 | #2289. Jail or Joyride | Realityang# | WA | 3ms | 3820kb | C++14 | 1.1kb | 2022-02-12 15:39:17 | 2022-05-06 07:22:41 |
Judging History
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);}
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;
}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);
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: 3ms
memory: 3732kb
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: 2ms
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'