QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#129389 | #5506. Hyperloop | Forever_Young# | WA | 167ms | 9784kb | C++14 | 2.6kb | 2023-07-22 18:00:49 | 2023-07-22 18:00:50 |
Judging History
answer
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
const int mo=998244353;
struct node{
int son[2],hash;
}tr[2000010];
int t,n,m,vis[100010],pre[100010],root[100010],tot,two[100010],maxd;
int dis[100010],res;
priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>> > q;
vector<pair<int,int> > edge[100010];
void getans(int x){
if (!x){
printf("%d\n",res);
return;
}
res++;
getans(pre[x]);
printf("%d ",x);
}
int newnode(){
++tot;
tr[tot].son[0]=tr[tot].son[1]=tr[tot].hash=0;
return tot;
}
void ins(int pwh,int wh,int l,int r,int x){
if (l==r){
tr[wh].hash=tr[pwh].hash+1;
return;
}
int mid=(l+r)/2;
if (x<=mid){
tr[wh].son[0]=newnode();
tr[wh].son[1]=tr[pwh].son[1];
ins(tr[pwh].son[0],tr[wh].son[0],l,mid,x);
}
else{
tr[wh].son[1]=newnode();
tr[wh].son[0]=tr[pwh].son[0];
ins(tr[pwh].son[1],tr[wh].son[1],mid+1,r,x);
}
tr[wh].hash=(1ll*tr[tr[wh].son[1]].hash*two[mid-l+1]+tr[tr[wh].son[0]].hash)%mo;
}
int comp(int wh,int pwh,int l,int r,int a,int b){
if (l==r) return tr[wh].hash+(a==l)>tr[pwh].hash+(b==l);
int mid=(l+r)/2;
int lh=tr[tr[wh].son[1]].hash;
int rh=tr[tr[pwh].son[1]].hash;
if (a>mid&&a<=r) lh=(lh+two[a-mid])%mo;
if (b>mid&&b<=r) rh=(rh+two[b-mid])%mo;
if (lh!=rh) return comp(tr[wh].son[1],tr[pwh].son[1],mid+1,r,a,b);
return comp(tr[wh].son[0],tr[pwh].son[0],l,mid,a,b);
}
int main(){
//freopen("H.in","r",stdin);
scanf("%d",&t);
two[0]=1;
for (int i=1;i<=100000;i++) two[i]=two[i-1]*100003%mo;
while (t--){
tot=0;
scanf("%d%d",&n,&m);
for (int i=0;i<m;i++){
int o,p,t;
scanf("%d%d%d",&o,&p,&t);
edge[o].pb(mp(p,t));
edge[p].pb(mp(o,t));
maxd=max(maxd,t);
}
for (int i=2;i<=n;i++) dis[i]=100000;
q.push(mp(0,1));
while (!q.empty()){
int now=q.top().se;
if (!vis[now]){
root[now]=newnode();
if (now!=1) ins(root[pre[now]],root[now],1,maxd,dis[now]-dis[pre[now]]);
for (int i=0;i<edge[now].size();i++)
if (dis[edge[now][i].fi]>dis[now]+edge[now][i].se){
dis[edge[now][i].fi]=dis[now]+edge[now][i].se;
pre[edge[now][i].fi]=now;
q.push(mp(dis[edge[now][i].fi],edge[now][i].fi));
}
else if (dis[edge[now][i].fi]==dis[now]+edge[now][i].se&&comp(root[now],root[pre[edge[now][i].fi]],1,maxd,edge[now][i].se,dis[edge[now][i].fi]-dis[pre[edge[now][i].fi]])==1) pre[edge[now][i].fi]=now;
vis[now]=1;
}
q.pop();
}
res=0;
getans(n);
printf("\n");
for (int i=1;i<=n;i++) edge[i].clear(),vis[i]=0;
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 9784kb
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: 167ms
memory: 8472kb
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 11)