QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#77903 | #5506. Hyperloop | jeffqi | RE | 167ms | 14064kb | C++14 | 2.9kb | 2023-02-15 20:46:26 | 2023-02-15 20:46:29 |
Judging History
answer
#include<bits/stdc++.h>
#define rep(i,a,b) for (int i = (a); i <= (b); ++i)
#define drep(i,a,b) for (int i = (a); i >= (b); --i)
#define grep(i,u) for (int i = head[u],v = e[i].v; i; v = e[i = e[i].nxt].v)
#define LL long long
#define il inline
#define pii pair<int,int>
#define pll pair<LL,LL>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
il LL read() {
LL x = 0,y = 1; char ch = getchar(); while (!isdigit(ch)) {if (ch == '-') y = -y; ch = getchar();}
while (isdigit(ch)) {x = x*10+ch-'0'; ch = getchar();} return x*y;
}
namespace qiqi {
const int N = 1e5+5,M = 3e5+5,V = 5e4,L = 30,P = 1e9+7; const LL INF = 0x3f3f3f3f3f3f3f3f;
int n,m,ecnt,head[N],cnt,pw[N],rt[N],pool[N*L],tp,pre[N],pos[N]; LL dis[N]; pll p[N]; bool vis[N];
struct Edge {int v,w,nxt;} e[M<<1]; il void add(int u,int v,int w) {e[++ecnt] = (Edge){v,w,head[u]}; head[u] = ecnt;}
il void Dij(int s) {
rep(i,1,n) {dis[i] = INF; vis[i] = 0;}
priority_queue<pll> q; q.push(mp(dis[s] = 0,s));
while (!q.empty()) {
int u = q.top().se; q.pop();
if (vis[u]) continue; vis[u] = 1;
grep(i,u) if (dis[u]+e[i].w < dis[v]) {
q.push(mp(-(dis[v] = dis[u]+e[i].w),v));
}
}
}
struct Node {int lc,rc,h;} a[N*L];
il int new_node() {
int x = tp ? pool[tp--] : ++cnt;
assert(x < N*L);
a[x] = (Node){0,0,0}; return x;
}
il void init(int n) {
pw[0] = 1; rep(i,1,n) pw[i] = 1LL*N*pw[i-1]%P;
}
il void push_up(int x,int l,int r) {
int mid = l+((r-l)>>1);
a[x].h = (1LL*a[a[x].lc].h*pw[r-mid]%P+a[a[x].rc].h)%P;
}
void upd(int &x,int y,int l,int r,int p) {
a[x = ++cnt] = a[y]; if (l == r) {++a[x].h; return;} int mid = l+((r-l)>>1);
p <= mid ? upd(a[x].lc,a[y].lc,l,mid,p) : upd(a[x].rc,a[y].rc,mid+1,r,p); push_up(x,l,r);
}
void del(int x,int l,int r,int p) {
if (!x) return; pool[++tp] = x; if (l == r) return; int mid = l+((r-l)>>1);
p <= mid ? del(a[x].lc,l,mid,p) : del(a[x].rc,mid+1,r,p);
}
bool qry(int x,int y,int l,int r) {
if (l == r) return a[x].h > a[y].h; int mid = l+((r-l)>>1);
return a[a[x].rc].h != a[a[y].rc].h ? qry(a[x].rc,a[y].rc,mid+1,r) : qry(a[x].lc,a[y].lc,l,mid);
}
il void print(int x,int c) {
if (!x) {
printf("%d\n",c); return;
}
print(pre[x],c+1);
printf("%d ",x);
if (!c) puts("");
}
void main() {
ecnt = cnt = tp = 0; n = read(); m = read();
rep(i,1,n) head[i] = rt[i] = 0;
rep(i,1,m) {
int u = read(),v = read(),w = read();
add(u,v,w); add(v,u,w);
}
Dij(1); rep(i,1,n) p[i] = mp(dis[i],i);
sort(p+1,p+n+1);
rep(i,1,n) {
int u = p[i].se;
grep(i,u) if (dis[u]+e[i].w == dis[v]) {
int x; upd(x,rt[u],1,V,e[i].w);
if (!rt[v] || qry(x,rt[v],1,V)) {
del(rt[v],1,V,pos[v]); rt[v] = x;
pre[v] = u; pos[v] = e[i].w;
}
else {
del(x,1,V,e[i].w);
}
}
}
print(n,0);
}
}
int main() {
qiqi::init(5e4); int T = read(); while (T--) qiqi::main(); return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 14064kb
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: 167ms
memory: 11932kb
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:
ok correct (600 test cases)
Test #3:
score: -100
Runtime Error
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...