A352题解
2026-07-26 17:45:23
发布于:浙江
13阅读
0回复
0点赞
这题是一道图的储存,要用邻接矩阵(二维数组)储存。而且是无向无权值图,所有如果有路:a[x][y]=a[y][x]=1(表示有路)。然后判断是否有路,最后分支判断输出。
废话少说上代码:
#include<bits/stdc++.h>
using namespace std;
int a[110][110];
int main() {
int n,m,q;
cin>>n>>m>>q;
for(int i=1;i<=m;i++){
int x,y;
cin>>x>>y;
a[x][y]=a[y][x]=1;//注意是无向图,正反都通。
}
for(int i=1;i<=q;i++){
int x,y;
cin>>x>>y;
if(a[x][y]||a[y][x]) cout<<"Cancel"<<endl;//注意正反都判断
else cout<<"Accepted"<<endl;
}
return 0;
}
求各位大佬点个赞
全部评论 1
1
2026-07-29 来自 浙江
0






有帮助,赞一个