#include <bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define pb push_back
#define ll long long
const int N=2005;
const int M=200050;
const int C=5;
const ll inf=4e18;
struct path{
int u,v;ll cost;
path(int a=0,int b=0,ll c=inf):u(a),v(b),cost(c){}
};
bool operator < (path a,path b){return a.cost>b.cost;}
path dist[N][N][C];
bool push(path tmp[C],path now,int o=C){
int i,c1=0,c2=0;
for(i=0;i<o&&tmp[i].cost!=inf;i++){
if(tmp[i].u==now.u&&tmp[i].v==now.v)return 0;
c1+=tmp[i].u==now.u;
c2+=tmp[i].v==now.v;
}
if(c1>1||c2>1||i==C)return 0;
if(tmp[i]<now)tmp[i]=now;
return 1;
}
vector<pii> E[N];
int ls[M],rs[M],tsz,root;
path node[M][C];
void pull(int c){
for(int i=0;i<C;i++){
node[c][i]=path();
for(int j=0;j<C;j++)
for(int k=0;k<C;k++)
if(node[ls[c]][j].v!=node[rs[c]][k].u)
push(node[c],path(node[ls[c]][j].u,node[rs[c]][k].v,node[ls[c]][j].cost+node[rs[c]][k].cost),i);
}
}
int x[M];
void Set(int&c,int ss,int se,int qi){
if(!c)c=++tsz;
if(ss==se){
for(int i=0;i<C;i++)node[c][i]=dist[x[ss]][x[ss+1]][i];
return;
}
int mid=ss+se>>1;
if(qi<=mid)Set(ls[c],ss,mid,qi);
else Set(rs[c],mid+1,se,qi);
pull(c);
}
int main(){
int n,m,t,l;
scanf("%i %i %i %i",&n,&m,&t,&l);
for(int i=1,u,v,w;i<=m;i++)scanf("%i %i %i",&u,&v,&w),E[u].pb({v,w}),E[v].pb({u,w});
for(int u=1;u<=n;u++){
priority_queue<pair<path,int>> pq;
for(auto e:E[u])pq.push({path(e.first,u,e.second),e.first});
while(pq.size()){
pair<path,int> now=pq.top();
pq.pop();
if(!push(dist[u][now.second],now.first))continue;
for(auto e:E[now.second])if(e.first!=now.first.v)
pq.push({path(now.first.u,now.second,now.first.cost+e.second),e.first});
}
}
for(int i=1;i<=l;i++)scanf("%i",&x[i]);
for(int i=1;i<l;i++)Set(root,1,l-1,i);
while(t--){
int i,y;
scanf("%i %i",&i,&y);
x[i]=y;
if(i!=1)Set(root,1,l-1,i-1);
if(i!=l)Set(root,1,l-1,i);
ll ans=node[root][0].cost;
printf("%lld\n",ans<inf?ans:-1);
}
return 0;
}
Compilation message
wild_boar.cpp: In function 'void Set(int&, int, int, int)':
wild_boar.cpp:46:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
46 | int mid=ss+se>>1;
| ~~^~~
wild_boar.cpp: In function 'int main()':
wild_boar.cpp:53:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
53 | scanf("%i %i %i %i",&n,&m,&t,&l);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
wild_boar.cpp:54:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
54 | for(int i=1,u,v,w;i<=m;i++)scanf("%i %i %i",&u,&v,&w),E[u].pb({v,w}),E[v].pb({u,w});
| ~~~~~^~~~~~~~~~~~~~~~~~~~~
wild_boar.cpp:66:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
66 | for(int i=1;i<=l;i++)scanf("%i",&x[i]);
| ~~~~~^~~~~~~~~~~~
wild_boar.cpp:70:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
70 | scanf("%i %i",&i,&y);
| ~~~~~^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
191 ms |
330744 KB |
Output is correct |
2 |
Correct |
192 ms |
330772 KB |
Output is correct |
3 |
Correct |
188 ms |
330744 KB |
Output is correct |
4 |
Correct |
191 ms |
330872 KB |
Output is correct |
5 |
Correct |
191 ms |
330744 KB |
Output is correct |
6 |
Correct |
189 ms |
330744 KB |
Output is correct |
7 |
Correct |
189 ms |
330744 KB |
Output is correct |
8 |
Correct |
191 ms |
330744 KB |
Output is correct |
9 |
Correct |
191 ms |
330744 KB |
Output is correct |
10 |
Correct |
194 ms |
330744 KB |
Output is correct |
11 |
Correct |
192 ms |
330744 KB |
Output is correct |
12 |
Correct |
194 ms |
330744 KB |
Output is correct |
13 |
Correct |
188 ms |
330748 KB |
Output is correct |
14 |
Correct |
193 ms |
330744 KB |
Output is correct |
15 |
Correct |
191 ms |
330744 KB |
Output is correct |
16 |
Correct |
195 ms |
330744 KB |
Output is correct |
17 |
Correct |
192 ms |
330872 KB |
Output is correct |
18 |
Correct |
192 ms |
330744 KB |
Output is correct |
19 |
Correct |
194 ms |
330892 KB |
Output is correct |
20 |
Correct |
188 ms |
330744 KB |
Output is correct |
21 |
Correct |
190 ms |
330688 KB |
Output is correct |
22 |
Correct |
188 ms |
330872 KB |
Output is correct |
23 |
Correct |
188 ms |
330744 KB |
Output is correct |
24 |
Correct |
188 ms |
330744 KB |
Output is correct |
25 |
Correct |
189 ms |
330732 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
191 ms |
330744 KB |
Output is correct |
2 |
Correct |
192 ms |
330772 KB |
Output is correct |
3 |
Correct |
188 ms |
330744 KB |
Output is correct |
4 |
Correct |
191 ms |
330872 KB |
Output is correct |
5 |
Correct |
191 ms |
330744 KB |
Output is correct |
6 |
Correct |
189 ms |
330744 KB |
Output is correct |
7 |
Correct |
189 ms |
330744 KB |
Output is correct |
8 |
Correct |
191 ms |
330744 KB |
Output is correct |
9 |
Correct |
191 ms |
330744 KB |
Output is correct |
10 |
Correct |
194 ms |
330744 KB |
Output is correct |
11 |
Correct |
192 ms |
330744 KB |
Output is correct |
12 |
Correct |
194 ms |
330744 KB |
Output is correct |
13 |
Correct |
188 ms |
330748 KB |
Output is correct |
14 |
Correct |
193 ms |
330744 KB |
Output is correct |
15 |
Correct |
191 ms |
330744 KB |
Output is correct |
16 |
Correct |
195 ms |
330744 KB |
Output is correct |
17 |
Correct |
192 ms |
330872 KB |
Output is correct |
18 |
Correct |
192 ms |
330744 KB |
Output is correct |
19 |
Correct |
194 ms |
330892 KB |
Output is correct |
20 |
Correct |
188 ms |
330744 KB |
Output is correct |
21 |
Correct |
190 ms |
330688 KB |
Output is correct |
22 |
Correct |
188 ms |
330872 KB |
Output is correct |
23 |
Correct |
188 ms |
330744 KB |
Output is correct |
24 |
Correct |
188 ms |
330744 KB |
Output is correct |
25 |
Correct |
189 ms |
330732 KB |
Output is correct |
26 |
Correct |
191 ms |
330744 KB |
Output is correct |
27 |
Correct |
889 ms |
332920 KB |
Output is correct |
28 |
Correct |
854 ms |
333188 KB |
Output is correct |
29 |
Correct |
1298 ms |
333176 KB |
Output is correct |
30 |
Correct |
1282 ms |
332920 KB |
Output is correct |
31 |
Correct |
1269 ms |
332976 KB |
Output is correct |
32 |
Correct |
1279 ms |
333048 KB |
Output is correct |
33 |
Correct |
1299 ms |
333112 KB |
Output is correct |
34 |
Correct |
1331 ms |
333056 KB |
Output is correct |
35 |
Correct |
1277 ms |
332920 KB |
Output is correct |
36 |
Correct |
1271 ms |
332920 KB |
Output is correct |
37 |
Correct |
1343 ms |
333224 KB |
Output is correct |
38 |
Correct |
1295 ms |
333048 KB |
Output is correct |
39 |
Correct |
1290 ms |
332920 KB |
Output is correct |
40 |
Correct |
1314 ms |
333244 KB |
Output is correct |
41 |
Correct |
1333 ms |
333012 KB |
Output is correct |
42 |
Correct |
1268 ms |
332924 KB |
Output is correct |
43 |
Correct |
1306 ms |
333096 KB |
Output is correct |
44 |
Correct |
1273 ms |
333036 KB |
Output is correct |
45 |
Correct |
1002 ms |
333320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
191 ms |
330744 KB |
Output is correct |
2 |
Correct |
192 ms |
330772 KB |
Output is correct |
3 |
Correct |
188 ms |
330744 KB |
Output is correct |
4 |
Correct |
191 ms |
330872 KB |
Output is correct |
5 |
Correct |
191 ms |
330744 KB |
Output is correct |
6 |
Correct |
189 ms |
330744 KB |
Output is correct |
7 |
Correct |
189 ms |
330744 KB |
Output is correct |
8 |
Correct |
191 ms |
330744 KB |
Output is correct |
9 |
Correct |
191 ms |
330744 KB |
Output is correct |
10 |
Correct |
194 ms |
330744 KB |
Output is correct |
11 |
Correct |
192 ms |
330744 KB |
Output is correct |
12 |
Correct |
194 ms |
330744 KB |
Output is correct |
13 |
Correct |
188 ms |
330748 KB |
Output is correct |
14 |
Correct |
193 ms |
330744 KB |
Output is correct |
15 |
Correct |
191 ms |
330744 KB |
Output is correct |
16 |
Correct |
195 ms |
330744 KB |
Output is correct |
17 |
Correct |
192 ms |
330872 KB |
Output is correct |
18 |
Correct |
192 ms |
330744 KB |
Output is correct |
19 |
Correct |
194 ms |
330892 KB |
Output is correct |
20 |
Correct |
188 ms |
330744 KB |
Output is correct |
21 |
Correct |
190 ms |
330688 KB |
Output is correct |
22 |
Correct |
188 ms |
330872 KB |
Output is correct |
23 |
Correct |
188 ms |
330744 KB |
Output is correct |
24 |
Correct |
188 ms |
330744 KB |
Output is correct |
25 |
Correct |
189 ms |
330732 KB |
Output is correct |
26 |
Correct |
191 ms |
330744 KB |
Output is correct |
27 |
Correct |
889 ms |
332920 KB |
Output is correct |
28 |
Correct |
854 ms |
333188 KB |
Output is correct |
29 |
Correct |
1298 ms |
333176 KB |
Output is correct |
30 |
Correct |
1282 ms |
332920 KB |
Output is correct |
31 |
Correct |
1269 ms |
332976 KB |
Output is correct |
32 |
Correct |
1279 ms |
333048 KB |
Output is correct |
33 |
Correct |
1299 ms |
333112 KB |
Output is correct |
34 |
Correct |
1331 ms |
333056 KB |
Output is correct |
35 |
Correct |
1277 ms |
332920 KB |
Output is correct |
36 |
Correct |
1271 ms |
332920 KB |
Output is correct |
37 |
Correct |
1343 ms |
333224 KB |
Output is correct |
38 |
Correct |
1295 ms |
333048 KB |
Output is correct |
39 |
Correct |
1290 ms |
332920 KB |
Output is correct |
40 |
Correct |
1314 ms |
333244 KB |
Output is correct |
41 |
Correct |
1333 ms |
333012 KB |
Output is correct |
42 |
Correct |
1268 ms |
332924 KB |
Output is correct |
43 |
Correct |
1306 ms |
333096 KB |
Output is correct |
44 |
Correct |
1273 ms |
333036 KB |
Output is correct |
45 |
Correct |
1002 ms |
333320 KB |
Output is correct |
46 |
Correct |
325 ms |
330872 KB |
Output is correct |
47 |
Correct |
2908 ms |
333136 KB |
Output is correct |
48 |
Correct |
3404 ms |
333156 KB |
Output is correct |
49 |
Correct |
3672 ms |
333296 KB |
Output is correct |
50 |
Correct |
3713 ms |
333048 KB |
Output is correct |
51 |
Correct |
3688 ms |
333072 KB |
Output is correct |
52 |
Correct |
3928 ms |
333428 KB |
Output is correct |
53 |
Correct |
3893 ms |
333576 KB |
Output is correct |
54 |
Correct |
3889 ms |
333388 KB |
Output is correct |
55 |
Correct |
3898 ms |
333448 KB |
Output is correct |
56 |
Correct |
3953 ms |
333516 KB |
Output is correct |
57 |
Correct |
3990 ms |
333464 KB |
Output is correct |
58 |
Correct |
3940 ms |
333456 KB |
Output is correct |
59 |
Correct |
3922 ms |
333672 KB |
Output is correct |
60 |
Correct |
3862 ms |
333380 KB |
Output is correct |
61 |
Correct |
3790 ms |
333356 KB |
Output is correct |
62 |
Correct |
3672 ms |
333320 KB |
Output is correct |
63 |
Correct |
3547 ms |
333432 KB |
Output is correct |
64 |
Correct |
1721 ms |
333432 KB |
Output is correct |
65 |
Correct |
1728 ms |
333460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
191 ms |
330744 KB |
Output is correct |
2 |
Correct |
192 ms |
330772 KB |
Output is correct |
3 |
Correct |
188 ms |
330744 KB |
Output is correct |
4 |
Correct |
191 ms |
330872 KB |
Output is correct |
5 |
Correct |
191 ms |
330744 KB |
Output is correct |
6 |
Correct |
189 ms |
330744 KB |
Output is correct |
7 |
Correct |
189 ms |
330744 KB |
Output is correct |
8 |
Correct |
191 ms |
330744 KB |
Output is correct |
9 |
Correct |
191 ms |
330744 KB |
Output is correct |
10 |
Correct |
194 ms |
330744 KB |
Output is correct |
11 |
Correct |
192 ms |
330744 KB |
Output is correct |
12 |
Correct |
194 ms |
330744 KB |
Output is correct |
13 |
Correct |
188 ms |
330748 KB |
Output is correct |
14 |
Correct |
193 ms |
330744 KB |
Output is correct |
15 |
Correct |
191 ms |
330744 KB |
Output is correct |
16 |
Correct |
195 ms |
330744 KB |
Output is correct |
17 |
Correct |
192 ms |
330872 KB |
Output is correct |
18 |
Correct |
192 ms |
330744 KB |
Output is correct |
19 |
Correct |
194 ms |
330892 KB |
Output is correct |
20 |
Correct |
188 ms |
330744 KB |
Output is correct |
21 |
Correct |
190 ms |
330688 KB |
Output is correct |
22 |
Correct |
188 ms |
330872 KB |
Output is correct |
23 |
Correct |
188 ms |
330744 KB |
Output is correct |
24 |
Correct |
188 ms |
330744 KB |
Output is correct |
25 |
Correct |
189 ms |
330732 KB |
Output is correct |
26 |
Correct |
191 ms |
330744 KB |
Output is correct |
27 |
Correct |
889 ms |
332920 KB |
Output is correct |
28 |
Correct |
854 ms |
333188 KB |
Output is correct |
29 |
Correct |
1298 ms |
333176 KB |
Output is correct |
30 |
Correct |
1282 ms |
332920 KB |
Output is correct |
31 |
Correct |
1269 ms |
332976 KB |
Output is correct |
32 |
Correct |
1279 ms |
333048 KB |
Output is correct |
33 |
Correct |
1299 ms |
333112 KB |
Output is correct |
34 |
Correct |
1331 ms |
333056 KB |
Output is correct |
35 |
Correct |
1277 ms |
332920 KB |
Output is correct |
36 |
Correct |
1271 ms |
332920 KB |
Output is correct |
37 |
Correct |
1343 ms |
333224 KB |
Output is correct |
38 |
Correct |
1295 ms |
333048 KB |
Output is correct |
39 |
Correct |
1290 ms |
332920 KB |
Output is correct |
40 |
Correct |
1314 ms |
333244 KB |
Output is correct |
41 |
Correct |
1333 ms |
333012 KB |
Output is correct |
42 |
Correct |
1268 ms |
332924 KB |
Output is correct |
43 |
Correct |
1306 ms |
333096 KB |
Output is correct |
44 |
Correct |
1273 ms |
333036 KB |
Output is correct |
45 |
Correct |
1002 ms |
333320 KB |
Output is correct |
46 |
Correct |
325 ms |
330872 KB |
Output is correct |
47 |
Correct |
2908 ms |
333136 KB |
Output is correct |
48 |
Correct |
3404 ms |
333156 KB |
Output is correct |
49 |
Correct |
3672 ms |
333296 KB |
Output is correct |
50 |
Correct |
3713 ms |
333048 KB |
Output is correct |
51 |
Correct |
3688 ms |
333072 KB |
Output is correct |
52 |
Correct |
3928 ms |
333428 KB |
Output is correct |
53 |
Correct |
3893 ms |
333576 KB |
Output is correct |
54 |
Correct |
3889 ms |
333388 KB |
Output is correct |
55 |
Correct |
3898 ms |
333448 KB |
Output is correct |
56 |
Correct |
3953 ms |
333516 KB |
Output is correct |
57 |
Correct |
3990 ms |
333464 KB |
Output is correct |
58 |
Correct |
3940 ms |
333456 KB |
Output is correct |
59 |
Correct |
3922 ms |
333672 KB |
Output is correct |
60 |
Correct |
3862 ms |
333380 KB |
Output is correct |
61 |
Correct |
3790 ms |
333356 KB |
Output is correct |
62 |
Correct |
3672 ms |
333320 KB |
Output is correct |
63 |
Correct |
3547 ms |
333432 KB |
Output is correct |
64 |
Correct |
1721 ms |
333432 KB |
Output is correct |
65 |
Correct |
1728 ms |
333460 KB |
Output is correct |
66 |
Correct |
1247 ms |
332920 KB |
Output is correct |
67 |
Correct |
997 ms |
331844 KB |
Output is correct |
68 |
Correct |
849 ms |
331000 KB |
Output is correct |
69 |
Correct |
1509 ms |
331844 KB |
Output is correct |
70 |
Correct |
3068 ms |
334528 KB |
Output is correct |
71 |
Correct |
7436 ms |
335564 KB |
Output is correct |
72 |
Correct |
7898 ms |
335556 KB |
Output is correct |
73 |
Correct |
8248 ms |
336040 KB |
Output is correct |
74 |
Correct |
8368 ms |
336268 KB |
Output is correct |
75 |
Correct |
8283 ms |
336184 KB |
Output is correct |
76 |
Correct |
8173 ms |
335536 KB |
Output is correct |
77 |
Correct |
7862 ms |
335640 KB |
Output is correct |
78 |
Correct |
6922 ms |
335440 KB |
Output is correct |
79 |
Correct |
8278 ms |
336220 KB |
Output is correct |
80 |
Correct |
8325 ms |
336264 KB |
Output is correct |
81 |
Correct |
8440 ms |
335844 KB |
Output is correct |
82 |
Correct |
8064 ms |
335928 KB |
Output is correct |
83 |
Correct |
8287 ms |
335532 KB |
Output is correct |
84 |
Correct |
7548 ms |
335844 KB |
Output is correct |
85 |
Correct |
5174 ms |
336304 KB |
Output is correct |