QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#80608#5506. HyperloopzhouhuanyiWA 120ms9740kbC++143.4kb2023-02-24 14:24:252023-02-24 14:24:27

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 14:24:27]
  • 评测
  • 测评结果:WA
  • 用时:120ms
  • 内存:9740kb
  • [2023-02-24 14:24:25]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
#include<vector>
#define N 100000
#define M 100
#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],p[N+1],pv[N+1],pvt[N+1],dst[N+1],dp[N+1][M+1];
vector<reads>E[N+1];
vector<int>A;
vector<int>B;
bool used[N+1];
bool cmp(int x,int y)
{
    return x>y;
}
bool cmp2(int x,int y)
{
    return dis[x]<dis[y];
}
void dijkstra()
{
    int top;
    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;
}
int main()
{
    int x,y,z,op;
    T=read();
    while (T--)
    {
	n=read(),m=read(),length=0;
	for (int i=1;i<=n;++i)
	{
	    E[i].clear(),dis[i]=inf,used[i]=pv[i]=pvt[i]=dst[i]=0;
	    for (int j=1;j<=100;++j) dp[i][j]=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();
	for (int i=1;i<=n;++i) p[i]=i;
	sort(p+1,p+n+1,cmp2);
	for (int i=2;i<=n;++i)
	    if (dis[p[i]]<=dis[n])
	    {
		for (int j=0;j<E[p[i]].size();++j)
		    if (dis[E[p[i]][j].num]+E[p[i]][j].data==dis[p[i]])
		    {
			if (!pv[p[i]])
			{
			    pv[p[i]]=E[p[i]][j].num;
			    for (int k=1;k<=100;++k) dp[p[i]][k]=dp[E[p[i]][j].num][k];
			    if (E[p[i]][j].data<=100) pvt[p[i]]=pvt[E[p[i]][j].num],dst[p[i]]=dst[E[p[i]][j].num],dp[p[i]][E[p[i]][j].data]++;
			    else pv[p[i]]=E[p[i]][j].num,dst[p[i]]=E[p[i]][j].data;
			}
			else
			{
			    A.clear(),B.clear(),x=p[i];
			    while (pvt[x]) A.push_back(dst[x]),x=pvt[x];
			    x=E[p[i]][j].num;
			    while (pvt[x]) B.push_back(dst[x]),x=pvt[x];
			    if (E[p[i]][j].data>100) B.push_back(E[p[i]][j].data);
			    sort(A.begin(),A.end(),cmp),sort(B.begin(),B.end(),cmp),op=-1;
			    for (int k=0;k<min(A.size(),B.size());++k)
				if (A[k]!=B[k])
				{
				    if (A[k]>B[k])
				    {
					op=0;
					break;
				    }
				    else
				    {
					op=1;
					break;
				    }
				}
			    if (A.size()!=B.size()) op=(A.size()<B.size());
			    if (op==-1)
			    {
				for (int k=100;k>=1;--k)
				    if (dp[E[p[i]][j].num][k]+(k==E[p[i]][j].data)!=dp[p[i]][k])
				    {
					if (dp[E[p[i]][j].num][k]+(k==E[p[i]][j].data)>dp[p[i]][k])
					{
					    op=1;
					    break;
					}
					else
					{
					    op=0;
					    break;
					}
				    }
			    }
			    if (op==1)
			    {
				pv[p[i]]=E[p[i]][j].num;
				for (int k=1;k<=100;++k) dp[p[i]][k]=dp[E[p[i]][j].num][k];
				if (E[p[i]][j].data<=100) pvt[p[i]]=pvt[E[p[i]][j].num],dst[p[i]]=dst[E[p[i]][j].num],dp[p[i]][E[p[i]][j].data]++;
				else pv[p[i]]=E[p[i]][j].num,dst[p[i]]=E[p[i]][j].data;
			    }
			}
		    }
	    }
	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: 3ms
memory: 9156kb

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
Wrong Answer
time: 120ms
memory: 9740kb

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

result:

wrong answer Contestant's path is not optimal lexicographically (test case 3)