QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#19862 | #2289. Jail or Joyride | Realityang# | WA | 1ms | 3820kb | C++14 | 1.2kb | 2022-02-12 15:20:02 | 2022-05-06 07:22:39 |
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);}
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();
}
详细
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'