multi-university contest3

contest 3

C dynamic graph

G 星际穿越

叉积的最小值为有效面积的最大值,因此要维护一个上凸包

M walking plan

分块求解,
题解
注意fb[][][]不一定是最优的,因此要再扫描后面的100条边。

ac code

floyd + 分块

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
87
88
89
90
91
92
93
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 60;
const ll INF = 0x3f3f3f3f3f3f3f3f;
ll e[maxn][maxn], fa[110][maxn][maxn], fb[210][maxn][maxn];
int n, m, q;
int s, t, k;
void mul(ll a[][maxn], ll b[][maxn], ll c[][maxn]){
ll ans[maxn][maxn];
memset(ans, 0x3f, sizeof(ans));
for(int i=1; i<=n; i++){
for(int j=1; j<=n; j++){
for(int k=1; k<=n; k++){
ans[i][j] = min(ans[i][j], a[i][k]+b[k][j]);
}
}
}
memcpy(c, ans, sizeof(ans));
}
void init(){
memcpy(fb[1], e, sizeof(e));
for(int i=2; i<=200; i++){
mul(e, fb[i-1], fb[i]);
}
memcpy(fa[1], fb[100], sizeof(e));
for(int i=2; i<=100; i++){
mul(fb[100], fa[i-1], fa[i]);
}
//之前算的不一定最优
for(int k=200-1; k>=1; k--){
for(int i=1; i<=100; i++){
for(int j=1; j<=100; j++){
fb[k][i][j] = min(fb[k][i][j], fb[k+1][i][j]);
}
}
}
}
ll query(int s, int t, int a, int b){
ll ans = INF;
for(int i=1; i<=n; i++){
ans = min(fa[a][s][i]+fb[b][i][t], ans);
}
return ans;
}
int main()
{
//ios::sync_with_stdio(false);
int tt;
//freopen("M.in", "r", stdin);
//freopen("G1.out", "w", stdout);
scanf("%d", &tt);
while(tt--){
scanf("%d%d", &n, &m);
int u, v, w;
memset(e, 0x3f, sizeof(e));
memset(fa, 0x3f, sizeof(fa));
memset(fb, 0x3f, sizeof(fb));
for(int i=0; i<m; i++){
scanf("%d%d%d", &u, &v, &w);
e[u][v] = min(e[u][v], 1ll*w);
}
//cout<<"11"<<endl;
init();
//cout<<"22"<<endl;
scanf("%d", &q);
ll ans;
while(q--){
scanf("%d%d%d", &s, &t, &k);
if(k<=100){
ans = fb[k][s][t];
if(ans == INF) printf("-1\n");
else printf("%lld\n", ans);
}
else{
int a, b;
a = (k-1)/100, b = k-a*100;
ans = query(s, t, a, b);
if(ans == INF){
printf("-1\n");
}
else{
printf("%lld\n", ans);
}
}
}
}
return 0;
}

未解决的问题

文章目录
  1. 1. C dynamic graph
  2. 2. G 星际穿越
  3. 3. M walking plan
    1. 3.1. ac code
  4. 4. 未解决的问题
{{ live2d() }}