QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#502292 | #125. Wild Boar | Rafi22 | 12 | 0ms | 3816kb | C++20 | 1.9kb | 2024-08-03 03:13:44 | 2024-08-03 03:13:44 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
auto&operator<<(auto&o,pair<auto,auto>p){return o<<"("<<p.first<<", "<<p.second<<")";}
auto operator<<(auto&o,auto x)->decltype(x.end(),o){o<<"{";int i=0;for(auto e:x)o<<","+!i++<<e;return o<<"}";}
#define debug(X...)cerr<<"["#X"]: ",[](auto...$){((cerr<<$<<"; "),...)<<endl;}(X)
#else
#define debug(...){}
#endif
#define ll long long
#define ld long double
#define endl '\n'
#define st first
#define nd second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define FOR(i,l,r) for(int i=(l);i<=(r);i++)
#define ROF(i,r,l) for(int i=(r);i>=(l);i--)
int inf=1000000007;
ll infl=1000000000000000007;
ll mod=1000000007;
const int N=17;
ll d[N][N][N];
bool odw[N][N][N];
vector<pair<int,ll>>G[N];
int x[N];
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n,m,q,L;
cin>>n>>m>>q>>L;
FOR(i,1,m)
{
int a,b,c;
cin>>a>>b>>c;
G[a].pb({b,c});
G[b].pb({a,c});
}
FOR(i,1,L) cin>>x[i];
while(q--)
{
int p;
cin>>p>>x[p];
FOR(i,1,L)
{
FOR(j,1,n)
{
FOR(l,1,n)
{
d[i][j][l]=infl;
odw[i][j][l]=0;
}
}
}
priority_queue<pair<ll,vector<int>>>Q;
Q.push({0,{1,x[1],x[1]}});
d[1][x[1]][x[1]]=0;
ll ans=infl;
while(sz(Q)>0)
{
int i=Q.top().nd[0],v=Q.top().nd[1],o=Q.top().nd[2];
Q.pop();
if(odw[i][v][o]) continue;
debug(i,v,o,d[i][v][o]);
odw[i][v][o]=1;
if(i==L)
{
ans=d[i][v][o];
break;
}
if(v==x[i+1]&&d[i][v][o]<d[i+1][v][o])
{
d[i+1][v][o]=d[i][v][o];
Q.push({-d[i+1][v][o],{i+1,v,o}});
}
for(auto [u,c]:G[v])
{
if(u==o) continue;
if(d[i][v][o]+c<d[i][u][v])
{
d[i][u][v]=d[i][v][o]+c;
Q.push({-d[i][u][v],{i,u,v}});
}
}
}
if(ans==infl) cout<<-1<<endl;
else cout<<ans<<endl;
}
return 0;
}
詳細信息
Subtask #1:
score: 12
Accepted
Test #1:
score: 12
Accepted
time: 0ms
memory: 3776kb
input:
5 5 1 10 1 4 10 2 4 2 2 5 4 3 5 4 4 5 7 2 4 5 3 5 3 5 4 2 1 10 1
output:
-1
result:
ok single line: '-1'
Test #2:
score: 12
Accepted
time: 0ms
memory: 3636kb
input:
5 10 1 10 1 2 8 1 3 5 1 4 2 1 5 1 2 3 7 2 4 9 2 5 6 3 4 10 3 5 10 4 5 6 4 2 4 3 5 3 1 4 3 5 3 5
output:
64
result:
ok single line: '64'
Test #3:
score: 12
Accepted
time: 0ms
memory: 3576kb
input:
5 10 1 10 1 2 8 1 3 4 1 4 2 1 5 10 2 3 10 2 4 10 2 5 6 3 4 10 3 5 2 4 5 10 5 1 2 1 4 5 1 5 3 1 8 4
output:
60
result:
ok single line: '60'
Test #4:
score: 12
Accepted
time: 0ms
memory: 3512kb
input:
6 10 1 10 1 3 3 1 4 5 1 5 9 1 6 10 2 3 4 2 5 5 2 6 1 3 6 4 4 6 6 5 6 8 4 3 6 4 1 3 6 4 3 5 1 1
output:
48
result:
ok single line: '48'
Test #5:
score: 12
Accepted
time: 0ms
memory: 3640kb
input:
6 10 1 10 1 2 10 1 3 9 1 5 6 1 6 9 2 4 3 2 5 4 2 6 9 3 5 2 4 5 6 4 6 8 4 6 2 3 2 3 1 3 5 4 9 1
output:
86
result:
ok single line: '86'
Test #6:
score: 12
Accepted
time: 0ms
memory: 3816kb
input:
6 10 1 10 1 2 7 1 4 10 1 5 9 1 6 9 2 3 7 2 4 3 3 4 1 3 5 4 4 6 2 5 6 3 6 3 1 3 6 4 6 4 3 1 5 2
output:
61
result:
ok single line: '61'
Test #7:
score: 12
Accepted
time: 0ms
memory: 3620kb
input:
7 10 1 10 1 2 4 1 3 8 1 5 10 1 7 5 2 5 5 2 7 4 3 4 8 3 6 9 4 7 6 5 6 9 2 1 2 1 2 1 2 1 2 1 9 2
output:
56
result:
ok single line: '56'
Test #8:
score: 12
Accepted
time: 0ms
memory: 3556kb
input:
7 10 1 10 1 4 8 1 5 9 1 6 5 1 7 5 2 4 1 2 6 9 2 7 6 3 5 5 3 7 2 5 6 7 6 5 3 4 6 3 6 4 7 4 4 4
output:
88
result:
ok single line: '88'
Test #9:
score: 12
Accepted
time: 0ms
memory: 3800kb
input:
7 10 1 10 1 3 1 1 4 5 1 5 8 2 3 4 2 7 9 3 4 8 3 7 5 4 5 1 5 6 8 6 7 2 6 5 2 5 6 5 6 5 7 6 4 3
output:
84
result:
ok single line: '84'
Test #10:
score: 12
Accepted
time: 0ms
memory: 3644kb
input:
7 10 1 10 1 3 4 1 4 3 1 5 7 1 6 5 1 7 2 2 3 8 2 4 6 4 7 7 5 6 10 6 7 4 3 2 3 1 3 1 3 1 3 2 9 3
output:
90
result:
ok single line: '90'
Test #11:
score: 12
Accepted
time: 0ms
memory: 3564kb
input:
8 10 1 10 1 2 4 1 7 4 1 8 7 2 3 7 2 4 2 3 7 5 3 8 8 4 5 5 5 6 5 6 8 3 3 5 7 5 6 3 5 3 6 4 9 2
output:
105
result:
ok single line: '105'
Test #12:
score: 12
Accepted
time: 0ms
memory: 3632kb
input:
8 10 1 10 1 3 6 1 7 3 1 8 1 2 3 10 2 4 6 2 8 9 3 5 3 4 6 5 5 7 7 6 8 7 5 2 6 8 4 5 2 5 3 6 10 7
output:
114
result:
ok single line: '114'
Test #13:
score: 12
Accepted
time: 0ms
memory: 3556kb
input:
8 10 1 10 1 2 6 1 3 9 1 6 7 2 8 6 3 5 10 4 6 4 4 7 1 4 8 8 5 7 7 6 8 9 2 8 5 6 2 3 5 6 4 8 3 5
output:
125
result:
ok single line: '125'
Test #14:
score: 12
Accepted
time: 0ms
memory: 3556kb
input:
8 10 1 10 1 2 5 1 5 8 1 8 3 2 6 5 2 7 8 3 4 5 3 8 4 4 6 4 5 6 1 5 7 5 7 4 5 1 6 4 7 4 8 6 10 1
output:
99
result:
ok single line: '99'
Test #15:
score: 12
Accepted
time: 0ms
memory: 3620kb
input:
9 10 1 10 1 3 1 1 6 6 1 9 6 2 4 5 2 9 3 3 5 4 4 5 10 6 7 6 7 8 8 8 9 6 3 5 2 6 2 8 5 1 3 7 2 8
output:
189
result:
ok single line: '189'
Test #16:
score: 12
Accepted
time: 0ms
memory: 3508kb
input:
9 10 1 10 1 8 9 1 9 5 2 6 8 2 7 10 3 5 8 3 7 5 4 5 3 4 8 4 5 9 7 6 9 9 4 7 5 2 7 5 8 4 6 1 7 2
output:
217
result:
ok single line: '217'
Test #17:
score: 12
Accepted
time: 0ms
memory: 3636kb
input:
9 10 1 10 1 4 8 1 9 10 2 3 3 2 5 10 3 9 1 4 8 5 5 7 6 6 7 2 6 8 7 8 9 10 2 9 6 4 5 8 6 3 9 3 4 7
output:
116
result:
ok single line: '116'
Test #18:
score: 12
Accepted
time: 0ms
memory: 3812kb
input:
9 10 1 10 1 3 6 1 4 1 2 4 1 2 6 7 3 4 6 3 9 1 5 6 2 5 8 6 7 8 8 7 9 9 1 6 7 6 9 7 1 5 9 3 7 6
output:
155
result:
ok single line: '155'
Test #19:
score: 12
Accepted
time: 0ms
memory: 3556kb
input:
10 10 1 10 1 3 6 1 9 5 2 4 4 2 6 2 3 4 10 5 8 1 5 10 7 6 7 8 7 10 2 8 9 8 10 3 10 9 1 2 8 4 7 4 2 3
output:
196
result:
ok single line: '196'
Test #20:
score: 12
Accepted
time: 0ms
memory: 3616kb
input:
10 10 1 10 1 4 5 1 8 6 2 8 9 2 9 7 3 9 4 3 10 3 4 7 5 5 6 10 5 10 10 6 7 8 9 5 4 6 5 8 2 8 9 8 3 9
output:
284
result:
ok single line: '284'
Test #21:
score: 12
Accepted
time: 0ms
memory: 3648kb
input:
5 10 1 10 1 2 1 1 3 7 1 4 6 1 5 10 2 3 2 2 4 4 2 5 5 3 4 1 3 5 10 4 5 3 2 1 5 1 4 2 5 4 1 5 7 5
output:
45
result:
ok single line: '45'
Test #22:
score: 12
Accepted
time: 0ms
memory: 3576kb
input:
5 10 1 10 1 2 4 1 3 10 1 4 5 1 5 6 2 3 2 2 4 1 2 5 1 3 4 9 3 5 10 4 5 10 4 2 3 1 4 3 1 3 2 3 10 1
output:
49
result:
ok single line: '49'
Test #23:
score: 12
Accepted
time: 0ms
memory: 3640kb
input:
5 10 1 10 1 2 10 1 3 8 1 4 2 1 5 10 2 3 7 2 4 2 2 5 4 3 4 3 3 5 7 4 5 1 3 1 2 4 5 4 3 2 5 2 10 2
output:
41
result:
ok single line: '41'
Test #24:
score: 12
Accepted
time: 0ms
memory: 3552kb
input:
5 10 1 10 1 2 7 1 3 7 1 4 4 1 5 8 2 3 6 2 4 10 2 5 1 3 4 9 3 5 4 4 5 6 1 4 3 1 2 4 2 1 2 4 1 2
output:
70
result:
ok single line: '70'
Test #25:
score: 12
Accepted
time: 0ms
memory: 3572kb
input:
5 10 1 10 1 2 10 1 3 8 1 4 9 1 5 3 2 3 3 2 4 3 2 5 10 3 4 1 3 5 1 4 5 7 4 3 1 3 4 2 4 5 2 3 9 2
output:
36
result:
ok single line: '36'
Test #26:
score: 12
Accepted
time: 0ms
memory: 3652kb
input:
5 10 1 10 1 2 5 1 3 7 1 4 2 1 5 6 2 3 5 2 4 2 2 5 8 3 4 8 3 5 3 4 5 1 3 2 5 4 1 2 4 3 1 2 2 2
output:
38
result:
ok single line: '38'
Subtask #2:
score: 0
Runtime Error
Dependency #1:
100%
Accepted
Test #27:
score: 0
Runtime Error
input:
20 40 1 100 1 9 61 1 17 2 1 20 2 2 8 35 2 16 11 2 17 4 3 5 19 3 18 52 4 5 4 4 6 89 4 11 52 5 6 59 5 10 77 5 12 24 5 13 82 5 16 55 5 18 25 6 7 98 6 9 59 6 15 37 7 10 42 7 17 71 8 10 37 8 19 31 9 10 74 9 14 25 9 15 70 9 18 39 10 14 1 11 20 46 12 17 48 12 20 36 13 17 32 13 20 77 14 18 73 15 16 50 15 17...
output:
result:
Subtask #3:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%
Subtask #4:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%