csp 2023-12 彩色路径

Southea Lv1

1.dfs——全部TLE

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
vector<edge> e[N];
int lenofpath; // 长度
int tmp_len;
int node_num; // 节点数量

void dfs(int src, int num, int n) // src起始节点,num路径中节点数目,n节点总数
{
if (l == num || src == n - 1)
{
if (src == n - 1)
lenofpath = max(lenofpath, tmp_len);
return;
}
else
{
// bool in=false;
for (auto &i : e[src])
{
if (tagc[c[i.des]])
continue;
if (tagn[src])
continue;
tmp_len += d[i.index];
node_num++;
tagc[c[i.des]] = 1;
tagn[src] = 1;
dfs(i.des, num - 1, n);
node_num--;
tmp_len -= d[i.index];
tagc[c[i.des]] = 0;
tagn[src] = 0;
}
}
return;
}
1
2
3
4
5
6 9 3 10
0 2 2 3 3 9
0 0 0 1 1 1 2 3 4
1 2 4 3 4 5 4 5 5
1 2 4 3 2 3 5 3 1
  • Title: csp 2023-12 彩色路径
  • Author: Southea
  • Created at : 2024-04-01 00:00:00
  • Updated at : 2024-04-01 16:58:10
  • Link: https://southea.github.io/2024/04/01/csp 2023-12 彩色路径/
  • License: This work is licensed under CC BY-NC-SA 4.0.
Comments
On this page
csp 2023-12 彩色路径