QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#88230#5506. Hyperloopmeaningful#ML 2ms5628kbC++141.9kb2023-03-15 18:04:212023-03-15 18:04:22

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-15 18:04:22]
  • 评测
  • 测评结果:ML
  • 用时:2ms
  • 内存:5628kb
  • [2023-03-15 18:04:21]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define ust unsigned short
#define fi first
#define sc second
using namespace std;
pair<ust,ust> M[12000000];
int cnt;
ust dis[100002];
int lst[100002],n,bg[100002],ed[100002];
ust lstl[100002];
vector<pair<int,ust> > e[100002];
pair<ust,ust> T[2][100002];int tot[2];
void gt(pair<ust,ust> *tmp,int x,ust o,int &tot)
{
	tot=0;
	for (int i=bg[x];i<ed[x];i++) if (M[i].fi>o)
	{
		tmp[tot++]=M[i];
	}
	else if (M[i].fi==o)
	{
		tmp[tot]=M[i];tmp[tot++].sc++;
	}else
	{
		if (cnt==bg[x] || M[cnt-1].fi>o)
		{
			tmp[tot++]={o,1};
		}
		tmp[tot++]=M[i];
	}
}
int chk(int x,int y,int z,ust ox,ust oy)
{
	gt(T[0],x,ox,tot[0]);
	gt(T[1],y,oy,tot[1]);
	int i;
	for (i=0;i<tot[0] && i<tot[1];i++)
	{
		if (T[0][i]!=T[1][i])
		{
			if (T[0][i]<T[1][i]) return 1;
			else return 0;
		}
	}
	return 0;
}
void dij()
{
	for (int i=0;i<=n;i++) dis[i]=65000,lst[i]=0;
	cnt=0;dis[1]=0;
	priority_queue<pair<int,int> >pq;
	pq.push({0,1});
	lst[1]=-1;
	while (!pq.empty())
	{
		int x=pq.top().second;pq.pop();
		if (x==n) break;
		bg[x]=cnt;
		gt(T[0],lst[x],lstl[x],tot[0]);
		for (int i=0;i<tot[0];i++) M[cnt++]=T[0][i];
		ed[x]=cnt;
		for (auto p:e[x]) if (!lst[p.fi] || (int)dis[p.fi]>(int)dis[x]+p.sc)
		{
			dis[p.fi]=dis[x]+p.sc;
			lst[p.fi]=x;lstl[p.fi]=p.sc;
			pq.push({-1.0*dis[p.fi],p.fi});
		}
		else if (lst[p.fi] && (int)dis[p.fi]==(int)dis[x]+p.sc)
		{
			if (chk(lst[p.fi],x,p.fi,lstl[p.fi],p.sc)) lst[p.fi]=x,lstl[p.fi]=p.sc;
		}
	}
	vector<int> ans;
	int nw=n;
	while (nw!=-1) ans.push_back(nw),nw=lst[nw];
	reverse(ans.begin(),ans.end());
	cout<<ans.size()<<endl;
	for (auto p:ans) cout<<p<<' ';cout<<endl;
}
int main()
{
	int TT;cin>>TT;
	while (TT--)
	{
		int m,i;cin>>n>>m;cnt=0;
		for (i=1;i<=n;i++) e[i].clear();
		for (i=1;i<=m;i++)
		{
			int u,v;cin>>u>>v;
			ust w;cin>>w;
			e[u].push_back({v,w});
			e[v].push_back({u,w});
		}
		dij();
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
4 6
1 2 1
1 3 2
2 3 1
2 4 2
3 4 1
1 4 4
6 11
1 2 9
2 3 12
3 4 3
4 5 5
5 6 10
6 1 22
2 4 9
3 6 1
4 6 5
2 5 2
3 5 8

output:

3
1 2 4 
5
1 2 5 3 6 

result:

ok correct (2 test cases)

Test #2:

score: -100
Memory Limit Exceeded

input:

600
320 1547
204 81 13768
232 97 9939
97 249 3719
201 109 14322
183 132 40881
142 143 1
275 186 24548
18 236 7907
30 317 11845
131 130 1
311 300 11704
141 92 41925
174 191 32128
119 120 1
184 183 1
310 309 1
283 270 25477
233 141 36076
212 92 13770
307 110 40656
218 137 14033
180 85 41892
200 199 44...

output:

184
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 10...

result: