Deleting Edges HDU - 6026 (最短路)

图论游戏挑战

Little Q is crazy about graph theory, and now he creates a game about graphs and trees.
There is a bi-directional graph with n nodes, labeled from 0 to n−1. Every edge has its length, which is a positive integer ranged from 1 to 9.
Now, Little Q wants to delete some edges (or delete nothing) in the graph to get a new graph, which satisfies the following requirements:
(1) The new graph is a tree with n−1 edges.
(2) For every vertice v(0<v<n)v(0<v<n), the distance between 0 and v on the tree is equal to the length of shortest path from 0 to v in the original graph.
Little Q wonders the number of ways to delete edges to get such a satisfied graph. If there exists an edge between two nodes i and j, while in another graph there isn’t such edge, then we regard the two graphs different.
Since the answer may be very large, please print the answer modulo 109+7.
Input
The input contains several test cases, no more than 10 test cases.
In each test case, the first line contains an integer n(1n50)n(1≤n≤50), denoting the number of nodes in the graph.
In the following n lines, every line contains a string with n characters. These strings describes the adjacency matrix of the graph. Suppose the jthj−th number of the ithi−th line isc(0c9)c(0≤c≤9), if c is a positive integer, there is an edge between i and j with length of c, if c=0, then there isn’t any edge between i and j.
The input data ensure that the i-th number of the i-th line is always 0, and the j-th number of the i-th line is always equal to the i-th number of the j-th line.
Output
For each test case, print a single line containing a single integer, denoting the answer modulo 109+7.
Sample Input
2
01
10
4
0123
1012
2101
3210
Sample Output
1
6

这题没写出来,有点不应该啊…
思路:先求出0到各点的最短路,然后枚举点,查看他的的临点,有哪些点到加上到这点的权值的和等于他的最短路。然后记录这些点的数量。最后每个点的数量相乘就是答案。
代码:

#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
#define mod 1000000007
#define INF 0x7f7f7f7f
using namespace std;
int graph[55][55];
int dis[55];
int n;
char inQ[55];
void spfa()
{
    queue<int>que;
    memset(dis,INF,sizeof(dis));
    dis[0]=0;
    que.push(0);
    inQ[0]=true;
    while(que.size())
    {
        int now=que.front();que.pop();
        inQ[now]=false;
        for(int i=0;i<n;i++)
        {
            if(!graph[now][i])
                continue;
            if(dis[i]>dis[now]+graph[now][i])
            {
                dis[i]=dis[now]+graph[now][i];
                if(!inQ[i])
                {
                    que.push(i);
                    inQ[i]=true;
                }
            }
        }
    }
}
int main()
{
    while(scanf("%d",&n)==1)
    {
        char s[55];
        for(int i=0;i<n;i++)
        {
            scanf("%s",s);
            for(int j=0;j<n;j++)
                graph[i][j]=s[j]-'0';
        }

        spfa();
        long long ans=1;
        for(int i=1;i<n;i++)
        {
            long long countt=0;
            for(int j=0;j<n;j++)
                if(graph[i][j])
                {
                    if(dis[i]==dis[j]+graph[i][j])
                        countt++;
                }
            ans=ans*countt%mod;
        }
        cout<<ans<<endl;
    }
    return 0;
}
<think>我们正在解决的是使用 `kubectl delete -f custom-resources.yaml` 命令时出现的两个错误: 1. 'installations.operator.tigera.io "default" not found' 2. 'apiservers.operator.tigera.io "default" not found' 根据错误信息,这两个CRD资源(CustomResourceDefinition)在删除时找不到名为"default"的实例。这可能是因为在custom-resources.yaml文件中定义了两个资源: - kind: Installation metadata: name: default - kind: APIServer metadata: name: default 但是当我们执行删除命令时,这两个资源可能已经被删除了(比如之前已经执行过删除),或者根本没有创建成功。 解决方案: 1. 检查资源是否存在: 我们可以先手动检查这两个资源是否存在,如果不存在,那么我们可以忽略这个错误,或者使用`--ignore-not-found`参数来避免错误。 2. 使用`--ignore-not-found`参数: 在删除命令中加入`--ignore-not-found`参数,这样即使资源不存在也不会报错。 具体操作: 步骤1:检查资源是否存在 对于'installations.operator.tigera.io'资源: kubectl get installations.operator.tigera.io default 对于'apiservers.operator.tigera.io'资源: kubectl get apiservers.operator.tigera.io default 如果这两个命令都返回“NotFound”,说明资源确实不存在,那么我们在删除时可以忽略。 步骤2:执行删除命令时忽略NotFound错误 kubectl delete -f custom-resources.yaml --ignore-not-found 这个命令会删除custom-resources.yaml文件中定义的所有资源,并且如果其中一些资源不存在,则忽略这些错误。 另外,如果custom-resources.yaml文件中还包含其他资源,我们也可以单独删除这两个资源(即使它们不存在): kubectl delete installations.operator.tigera.io default --ignore-not-found kubectl delete apiservers.operator.tigera.io default --ignore-not-found 然后再执行: kubectl delete -f custom-resources.yaml 但是,通常我们不需要单独删除,因为使用`--ignore-not-found`参数就可以解决。 注意:如果custom-resources.yaml文件中包含其他资源,我们希望全部删除,那么直接使用`kubectl delete -f custom-resources.yaml --ignore-not-found`是方便的。 补充:为什么会出现这种情况? 可能是因为之前已经删除过这些资源,再次删除时就会报错。或者是在安装过程中创建资源失败,导致资源不存在。 参考引用[2]中提到的Calico安装分为两个步骤:tigera-operator.yaml和custom-resources.yaml。在卸载时,通常也是按相反顺序删除这两个文件定义的资源。 因此,我们建议的完整卸载步骤是: 1. 删除custom-resources.yaml(使用--ignore-not-found避免因资源不存在而报错): kubectl delete -f custom-resources.yaml --ignore-not-found 2. 删除tigera-operator.yaml(同样使用--ignore-not-found): kubectl delete -f tigera-operator.yaml --ignore-not-found 这样即使有些资源已经被删除,也不会影响整个卸载过程。 另外,引用[3]中提到如果安装失败可以执行`kubeadm reset`,但那是重置整个集群,我们这里只针对Calico的卸载。 总结命令: 针对用户当前问题,只需在删除custom-resources.yaml时加上`--ignore-not-found`即可: kubectl delete -f custom-resources.yaml --ignore-not-found 然后可以继续删除tigera-operator(如果需要): kubectl delete -f tigera-operator.yaml --ignore-not-found 注意:如果用户只是想重新安装Calico,那么应该先卸载再安装。卸载后,确保相关资源都被删除,再重新执行安装步骤。 另外,如果用户使用的是引用[4]中提到的不同版本的Calico,请注意custom-resources.yaml文件的内容可能有所不同,但删除方式相同。 后,生成相关问题。 </think>### 解决 `kubectl delete` 报 "not found" 错误的方法 出现 `installations.operator.tigera.io "default" not found` 和 `apiservers.operator.tigera.io "default" not found` 错误的原因是 Calico 卸载流程中的常见问题。以下是系统化解决方案: #### 根本原因分析 1. **资源已提前删除**:`default` 资源可能在之前操作中已被删除 2. **资源名称不匹配**:YAML 文件中资源名可能不是 `default` 3. **卸载顺序错误**:应先删除自定义资源再删除 Operator[^2] --- ### 解决方案 #### 方法一:强制忽略缺失资源(推荐) ```bash kubectl delete -f custom-resources.yaml --ignore-not-found ``` - `--ignore-not-found` 参数会跳过已删除的资源 - 适用于大多数清理场景 #### 方法二:精确删除特定资源 ```bash # 单独删除可能存在的自定义资源 kubectl delete installations.operator.tigera.io default --ignore-not-found kubectl delete apiservers.operator.tigera.io default --ignore-not-found # 再删除其他资源 kubectl delete -f custom-resources.yaml ``` #### 方法三:完整卸载 Calico ```bash # 1. 删除自定义资源 kubectl delete -f custom-resources.yaml --ignore-not-found # 2. 删除 Operator kubectl delete -f tigera-operator.yaml --ignore-not-found # 3. 清理残余资源(谨慎操作) kubectl delete crd -l operator.tigera.io/name=tigera-operator ``` --- ### 验证卸载结果 ```bash # 检查自定义资源实例 kubectl get installations.operator.tigera.io kubectl get apiservers.operator.tigera.io # 检查 Operator 状态 kubectl get pods -n tigera-operator # 检查 CRD 是否存在 kubectl get crd | grep tigera ``` > ⚠️ **重要提示**: > 1. 如果重装 Calico,需确认集群 CIDR 配置一致: > ```bash > kubectl cluster-info dump | grep cluster-cidr > ``` > 2. 安装新版本时,使用官方新 manifest: > ```bash > wget https://raw.githubusercontent.com/projectcalico/calico/v3.27.0/manifests/tigera-operator.yaml > ```[^4] --- ### 预防措施 1. **声明式删除**:始终使用 `kubectl delete -f <file>.yaml --ignore-not-found` 2. **卸载顺序**: ```mermaid graph LR A[删除 custom-resources.yaml] --> B[删除 tigera-operator.yaml] ``` 3. **版本一致性**:安装和卸载使用相同版本的 manifest 文件[^2][^4]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值