QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#20043#2289. Jail or JoyrideThe_Nobody#WA 1ms4444kbC++142.6kb2022-02-14 16:46:402022-05-03 08:57:49

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-03 08:57:49]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:4444kb
  • [2022-02-14 16:46:40]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define Il inline
#define Re register
#define mem(u,v) memset(u,v,sizeof(u))
#define rep(i,a,b) for(Re ll i=(a),KKK##i=(b);i<=KKK##i;i++)
#define drep(i,a,b) for(Re ll i=(a),KKK##i=(b);i>=KKK##i;i--)
#define go(u) for(ll i=head[u],v=e[i].to;i;i=e[i].nxt,v=e[i].to)
#define _go(u) for(ll i=Head[u],v=E[i].to;i;i=E[i].nxt,v=E[i].to)
#define __go(u) for(ll i=Head[u],v=e[i].to;i;i=e[i].nxt,v=e[i].to)
#define writesp(x) write(x),putchar(' ')
#define writeln(x) write(x),puts("")
using namespace std;
Il ll read(){ll sum=0,f=0;char ch=getchar();for(;!isdigit(ch);ch=getchar())f|=(ch=='-');for(;isdigit(ch);ch=getchar())sum=((sum<<1)+(sum<<3)+(ch^48));return f?-sum:sum;}
void write(const ll x){if(x<0){putchar('-');write(-x);return;}if(x>9)write(x/10);putchar(x%10+'0');}
char getc(){char c=getchar();while(c!='*'&&c!='.')c=getchar();return c;}
#define N 330
ll n,m,p,t,x,y,z,dis[N][N],s[N],top,ds[N],mx,tot,head[N],in[N],inf=4557430888798830399;bool vis[N],vs[N],flag[N];
struct node{ll to,dis,nxt;}e[N*N];
void add(ll f,ll to,ll dis){/*cout<<f<<' '<<to<<' '<<dis<<endl;*/e[++tot].to=to;e[tot].dis=dis;e[tot].nxt=head[f];head[f]=tot;}
queue<ll>q;
int main(){
	n=read(),m=read(),p=read(),t=read();mem(dis,0x3f);
//	cout<<dis[0][0]<<endl;
	rep(i,1,m)x=read(),y=read(),z=read(),dis[x][y]=dis[y][x]=z,in[x]++,in[y]++;
	rep(i,1,n)dis[i][i]=0;
	rep(k,1,n)rep(i,1,n)rep(j,1,n)dis[i][j]=min(dis[i][k]+dis[k][j],dis[i][j]);
	rep(i,1,n)if(in[i]==1)flag[i]=1;
	rep(i,1,n)in[i]=0;
//	rep(i,1,n){
//		rep(j,1,n)writesp(dis[i][j]==inf?-1:dis[i][j]);puts("");
//	}
	if(dis[p][t]==inf){puts("impossible");return 0;}
	rep(i,1,n){
		top=0;mx=0;
		rep(j,1,n){
			if(dis[i][j]>mx&&dis[i][j]!=inf)top=0,s[++top]=j,mx=dis[i][j];
			else if(dis[i][j]==mx)s[++top]=j;
		}
		rep(j,1,top)add(i,s[j],dis[i][s[j]]);
	}
	q.push(t);vis[t]=1;
	while(!q.empty()){
		ll u=q.front();q.pop();
		go(u)if(!vis[v])vis[v]=1,q.push(v);
	}
	rep(u,1,n)if(vis[u]&&!flag[u]){
		go(u)if(vis[v]){
			in[v]++;
		}
	}
//	rep(i,1,n)cout<<in[i]<<' ';puts("");
//	rep(i,1,n)cout<<flag[i]<<' ';puts("");
//	rep(i,1,n)cout<<vis[i]<<' ';puts("");
	rep(i,1,n)if(!in[i]&&vis[i]&&!flag[i])q.push(i);
	while(!q.empty()){
		ll u=q.front();q.pop();
//		cout<<"in"<<u<<endl;
		go(u)if(vis[v]&&!flag[u]){
			in[v]--;
//			cout<<"GG"<<u<<' '<<v<<endl;
			ds[v]=max(ds[v],ds[u]+e[i].dis);
			if(!vs[v])vs[v]=1,q.push(v);
		}
	}
//	rep(i,1,n)cout<<in[i]<<" ";puts("");
//	rep(i,1,n)cout<<ds[i]<<" ";puts("");
	rep(i,1,n)if(in[i])return puts("impossible"),0;
	mx=0;
	rep(i,1,n)mx=max(mx,ds[i]);
	writeln(mx+dis[p][t]);
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 4444kb

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:

4960014

result:

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