QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#307795 | #5034. >.< | lnyx | 0 | 1ms | 3732kb | C++14 | 2.4kb | 2024-01-19 09:32:43 | 2024-01-19 09:32:44 |
answer
// 距离退役还有 44 天
#include<cstdio>
#include<iostream>
#include<queue>
#include<vector>
#include<ctime>
#define eb emplace_back
using namespace std;
namespace IO{
template<typename T> inline void rd(T &x){
x=0; bool f=0; char c=getchar();
while(c<'0'||c>'9') f|=c=='-',c=getchar();
while('0'<=c&&c<='9') x=((x<<3)+(x<<1))+(c^48),c=getchar();
x=f?-x:x;
}
template<typename T,typename ...Args> inline void rd(T &x,Args &...args){ rd(x),rd(args...); }
template<typename T> inline void wt(char c,T x){
static int stk[114]; int top=0;
if(x<0) x=-x,putchar('-');
do stk[++top]=x%10,x/=10; while(x);
while(top) putchar(stk[top--]+'0');
putchar(c);
}
template<typename T,typename ...Args> inline void wt(char c,T x,Args ...args){ wt(c,x),wt(c,args...); }
template<typename T,typename ...Args> inline void wt(char c1,char c2,T x,Args ...args){ wt(c2,x),wt(c2,args...),putchar(c1); }
}
using IO::rd;
using IO::wt;
typedef pair<int,int> PII;
const int INF=1e9;
const int N=1007;
int n,m,K;
int tr[N][N],val[N],ne[N],idx;
bool flag[N];
int p[N],cnt;
vector<PII>g[N];
inline void ins(int x){
int u=0;
for(int i=1;i<=cnt;i++){
if(!tr[u][p[i]]) tr[u][p[i]]=++idx;
u=tr[u][p[i]],val[u]=p[i];
}
flag[u]=x;
}
inline void build(){
queue<int>q;
for(int i=1;i<=n;i++){
if(tr[0][i]) q.push(tr[0][i]);
}
while(q.size()){
int u=q.front(); q.pop();
for(int i=1;i<=n;i++){
int &v=tr[u][i];
if(!tr[u][i]) v=tr[ne[u]][i];
else{
ne[v]=tr[ne[u]][i];
q.push(v);
}
}
}
}
int dist[N];
inline int dij(int S){
for(int i=0;i<=idx;i++) dist[i]=INF;
priority_queue<PII>q;
dist[S]=0,q.push({0,S});
int ans=INF;
while(q.size()){
int u=q.top().second; q.pop();
if(flag[u]) continue;
flag[u]=1;
for(PII A:g[val[u]]){
int v=tr[u][A.first],w=A.second;
if(flag[v]) continue;
if(dist[v]>dist[u]+w){
dist[v]=dist[u]+w,q.push({-dist[v],v});
if(val[v]==n) ans=min(ans,dist[v]);
}
}
}
return ans;
}
int main(){
#ifndef ONLINE_JUDGE
freopen("in.in","r",stdin);
freopen("out.out","w",stdout);
#endif
rd(n,m,K);
for(int i=1;i<=m;i++){
int u,v,w; rd(u,v,w);
g[u].eb(v,w);
}
while(K--){
rd(cnt);
for(int i=1;i<=cnt;i++) rd(p[i]);
ins(1);
}
for(int i=1;i<=n;i++) p[cnt=1]=i,ins(0);
build();
wt('\n',dij(tr[0][1]));
// for(int i=0;i<=idx;i++) cerr<<flag[i]<<" ";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3732kb
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:
1000000000
result:
wrong answer 1st lines differ - expected: '1970522617', found: '1000000000'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Runtime Error
Test #11:
score: 0
Runtime Error
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%