QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#80564#5506. HyperloopzhouhuanyiML 357ms31132kbC++143.4kb2023-02-24 11:29:092023-02-24 11:29:11

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-02-24 11:29:11]
  • 评测
  • 测评结果:ML
  • 用时:357ms
  • 内存:31132kb
  • [2023-02-24 11:29:09]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
#include<cassert>
#define N 100000
#define inf 1e9
using namespace std;
int read()
{
    char c=0;
    int sum=0;
    while (c<'0'||c>'9') c=getchar();
    while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
    return sum;
}
struct reads
{
    int num,data;
    bool operator < (const reads &t)const
    {
	return data>t.data; 
    }
};
priority_queue<reads>q;
int T,n,m,tong[N+1],length,dis[N+1],dis2[N+1],pv[N+1],in[N+1],dque[N+1],top;
bool used[N+1];
vector<reads>E[N+1];
vector<reads>ES[N+1];
vector<reads>dist[N+1];
vector<reads>c;
void adder(vector<reads>&a,int b)
{
    int ps=-1;
    for (int i=0;i<a.size();++i)
	if (a[i].num==b)
	{
	    c=a,c[i].data++;
	    return;
	}
    for (int i=0;i<a.size();++i)
	if (a[i].num>b)
	    ps=i;
    for (int i=0;i<=ps;++i) c.push_back(a[i]);
    c.push_back((reads){b,1});
    for (int i=ps+1;i<a.size();++i) c.push_back(a[i]);
    return;
}
bool operator > (vector<reads>&a,vector<reads>&b)
{
    for (int i=0;i<min(a.size(),b.size());++i)
	if (a[i].num!=b[i].num||a[i].data!=b[i].data)
	{
	    if (a[i].num>b[i].num||(a[i].num==b[i].num&&a[i].data>b[i].data)) return 1;
	    else return 0;
	}
    return a.size()>b.size();
}
bool cmp2(int x,int y)
{
    return dis[x]<dis[y];
}
void dijkstra()
{
    int top;
    for (int i=1;i<=n;++i) dis[i]=inf,used[i]=0;
    dis[1]=0,q.push((reads){1,0});
    while (!q.empty())
    {
	top=q.top().num,q.pop();
	if (used[top]) continue;
	used[top]=1;
	for (int i=0;i<E[top].size();++i)
	    if (dis[E[top][i].num]>dis[top]+E[top][i].data)
		dis[E[top][i].num]=dis[top]+E[top][i].data,q.push((reads){E[top][i].num,dis[E[top][i].num]});
    }
    return;
}
void dijkstra2()
{
    int top;
    for (int i=1;i<=n;++i) dis2[i]=inf,used[i]=0;
    dis2[n]=0,q.push((reads){n,0});
    while (!q.empty())
    {
	top=q.top().num,q.pop();
	if (used[top]) continue;
	used[top]=1;
	for (int i=0;i<E[top].size();++i)
	    if (dis2[E[top][i].num]>dis2[top]+E[top][i].data)
		dis2[E[top][i].num]=dis2[top]+E[top][i].data,q.push((reads){E[top][i].num,dis2[E[top][i].num]});
    }
    return;
}
void topo_sort()
{
    int top;
    queue<int>q;
    q.push(1);
    while (!q.empty())
    {
	top=q.front(),q.pop();
	for (int i=0;i<ES[top].size();++i)
	{
	    in[ES[top][i].num]--;
	    if (!in[ES[top][i].num]) q.push(ES[top][i].num);
	    adder(dist[top],ES[top][i].data);
	    if (c>dist[ES[top][i].num]) dist[ES[top][i].num]=c,pv[ES[top][i].num]=top;
	    c.clear(),c.shrink_to_fit();
	}
        dist[top].clear(),dist[top].shrink_to_fit();
    }
    return;
}
int main()
{
    int x,y,z;
    T=read();
    while (T--)
    {
	n=read(),m=read(),length=0;
	for (int i=1;i<=n;++i) E[i].clear(),ES[i].clear(),dist[i].clear(),in[i]=0;
	for (int i=1;i<=m;++i) x=read(),y=read(),z=read(),E[x].push_back((reads){y,z}),E[y].push_back((reads){x,z});
	dijkstra(),dijkstra2();
	for (int i=1;i<=n;++i) used[i]=(dis[i]+dis2[i]==dis[n]);
	for (int i=1;i<=n;++i)
	    if (used[i])
		for (int j=0;j<E[i].size();++j)
		    if (used[E[i][j].num]&&dis[i]+E[i][j].data==dis[E[i][j].num])
			ES[i].push_back(E[i][j]),in[E[i][j].num]++;
	topo_sort(),x=n,tong[++length]=n;
	while (x!=1) x=pv[x],tong[++length]=x;
	printf("%d\n",length);
	for (int i=length;i>=1;--i) printf("%d ",tong[i]);
	puts("");
    }
    return 0;
}

详细

Test #1:

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

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: 0
Accepted
time: 164ms
memory: 11592kb

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 86 89 90 91 92 93 94 95 96 97 98 99 100 101 102 10...

result:

ok correct (600 test cases)

Test #3:

score: 0
Accepted
time: 357ms
memory: 31132kb

input:

4
100000 220000
48940 43355 42347
77914 77913 1
45236 82683 42904
22563 16038 34866
81537 81538 43088
49803 51485 25497
63071 25523 14336
44102 39850 43782
13607 92386 16724
98711 73651 46840
17775 16801 28765
5757 98829 13508
85095 48444 1
9198 43003 32678
14461 14462 1
20245 48742 18138
89120 8911...

output:

35000
1 24721 24648 24679 96004 24661 24986 24619 24234 24553 24884 24453 24398 25109 25096 43056 43055 43054 43053 43052 43051 43050 43049 43048 43047 43046 43045 43044 43043 43042 43041 43040 43039 43038 43037 43036 43035 43034 43033 43032 43031 43030 43029 43028 43027 43026 43025 43024 43023 4302...

result:

ok correct (4 test cases)

Test #4:

score: -100
Memory Limit Exceeded

input:

4
100000 160000
5533 94547 28459
14992 20984 20548
70133 92512 27510
9013 9012 304
13621 40571 47787
305 306 262
6987 6988 135
16234 16992 40656
26246 49196 27701
19103 60272 44055
91532 91531 38290
70778 68341 35147
32524 32523 13
85786 50300 40970
49277 29735 13942
43446 34519 42455
77623 17031 34...

output:


result: