QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#850644 | #5034. >.< | BINYU | 0 | 0ms | 0kb | C++14 | 3.0kb | 2025-01-10 10:47:06 | 2025-01-10 10:47:12 |
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pli pair <ll,int>
const int N = 2e5;
int n,m,k,u,v,w,p,a[N + 5],cnt;
int id[2 * N + 5],fail[2 * N + 5];
int vis[2 * N + 5];
ll dis[2 * N + 5],ans;
struct edge
{
int v,w;
bool operator < (const edge &y)const
{
return v < y.v;
}
};
vector <edge> e[N + 5],now;
set <pair <int,int> > s;
map <int,int> mp[2 * N + 5];
queue <int> q;
struct Segment_Tree
{
#define ls a[id].l
#define rs a[id].r
struct node
{
int l,r,val,id;
}a[60 * N + 5];
int cntnode;
int update(int id,int l,int r,int x,int v,int w)
{
a[++cntnode] = a[id];id = cntnode;
if(l == r)
{
if(w != -1)a[id].val = w;
return a[id].id = v,id;
}
int mid = l + r >> 1;
if(x <= mid)ls = update(ls,l,mid,x,v,w);
else rs = update(rs,mid + 1,r,x,v,w);
return id;
}
int query(int id,int l,int r,int x)
{
if(l == r)return a[id].id;
int mid = l + r >> 1;
if(x <= mid)return query(ls,l,mid,x);
return query(rs,mid + 1,r,x);
}
int get(int id,int l,int r,int u,vector <edge> &ne)
{
if(!id)return 0;
if(l == r)return ne.push_back({a[id].id,a[id].val}),0;
int mid = l + r >> 1;
ls = get(ls,l,mid,u,ne);
rs = get(rs,mid + 1,r,u,ne);
return 0;
}
}st;
int rt[2 * N + 5];
void dij(int s)
{
priority_queue <pli,vector <pli>,greater <pli> > q;
memset(dis,0x3f,sizeof(dis));
dis[s] = 0;q.push({dis[s],s});
while(!q.empty())
{
int u = q.top().second;q.pop();
if(vis[u])continue;vis[u] = 1;
now.clear();
rt[u] = st.get(rt[u],1,n,u,now);
for(auto v : now)
if(!vis[v.v]&&dis[u] + v.w < dis[v.v])
dis[v.v] = dis[u] + v.w,
q.push({dis[v.v],v.v});
}
}
int main()
{
freopen("compete.in","r",stdin);
freopen("compete.out","w",stdout);
scanf("%d %d %d",&n,&m,&k);
for(int i = 1;i <= m;i++)
scanf("%d %d %d",&u,&v,&w),
e[u].push_back({v,w}),
s.insert({u,v});
int Rt = n + 1;
for(int i = 1;i <= n;i++)mp[Rt][i] = i,id[i] = i;
cnt = Rt;
while(k--)
{
scanf("%d",&p);
for(int i = 1;i <= p;i++)scanf("%d",&a[i]);
int f = 1;
for(int i = 2;i <= p;i++)
if(s.find({a[i - 1],a[i]}) == s.end())
f = 0;
if(!f)continue;
int now = n + 1;
for(int i = 1;i <= p;i++)
{
if(mp[now].find(a[i]) == mp[now].end())
mp[now][a[i]] = ++cnt,id[cnt] = a[i];
now = mp[now][a[i]];
}
vis[now] = 2;
}
for(int i = 1;i <= n;i++)
{
for(auto v : e[i])
rt[i] = st.update(rt[i],1,n,v.v,v.v,v.w);
fail[i] = Rt,q.push(i);
}
while(!q.empty())
{
int u = q.front();q.pop();
if(u > n)rt[u] = rt[fail[u]];
vis[u] |= vis[fail[u]];
for(auto now : mp[u])
{
int v = now.first,nxt = now.second;
rt[u] = st.update(rt[u],1,n,v,nxt,-1);
if(u <= n)fail[nxt] = v;
else fail[nxt] = st.query(rt[fail[u]],1,n,v);
q.push(nxt);vis[nxt] |= vis[u];
}
}
dij(1);ans = 1e18;
for(int i = 1;i <= cnt;i++)
if(vis[i] != 2&&id[i] == n)ans = min(ans,dis[i]);
if(ans >= 1e18)puts("-1");
else cout<<ans;
}
详细
Subtask #1:
score: 0
Dangerous Syscalls
Test #1:
score: 0
Dangerous Syscalls
input:
35 100 0 34 7 447733879 24 20 187005344 14 34 654502303 2 31 865194349 20 33 9517055 33 15 991889891 24 33 395599993 13 16 237525328 9 5 373850826 30 34 391470240 10 7 650077565 26 10 400825980 34 27 189924713 19 27 907609573 20 10 614945312 10 5 960007605 1 7 984076202 32 25 539699728 24 31 2553027...
output:
result:
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Dangerous Syscalls
Test #11:
score: 0
Dangerous Syscalls
input:
50000 200000 1 7542 37166 116613326 3581 43961 629220971 12873 42953 440313807 31744 5286 697832848 25882 12748 106667302 34760 29676 181570340 41570 9240 885513989 22227 35688 63657981 43180 29194 174058940 8977 41899 48262624 7465 18291 600002514 46925 9281 951474878 2115 31162 373758881 5386 3798...
output:
result:
Subtask #4:
score: 0
Skipped
Dependency #2:
0%