简单图判定
//简单图判定
#include<bits/stdc++.h>
using namespace std;
int n, m;
int a[1001][1001];
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
for (int i = 1; i <= m; i++){
int x, y;
cin >> x >> y;
if (x == y || a[x][y]){
cout << "No" << '\n';
return 0;
}
a[x][y] = a[y][x] = 1;
}
cout << "Yes" << '\n';
}
竞赛图数量
竞赛图基于n阶无向完全图,给每条边任意赋予一个方向的图就是竞赛图
//竞赛图数量
#include<bits/stdc++.h>
using namespace std;
int n;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n;
long long ans = 1LL << ((n * (n - 1)) / 2);
cout << ans << '\n';
}
顶点度数统计
//顶点度数统计
#include<bits/stdc++.h>
using namespace std;
int n, m;
int d[1001];
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
for (int i = 1; i <= m; i++){
int x, y;
cin >> x >> y;
d[x]++;
d[y]++;
}
for (int i = 1; i <= n; i++){
cout << d[i] << ' ';
}
cout << '\n';
}
判断图是否同构
//判断图是否同构
#include<bits/stdc++.h>
using namespace std;
int n, m, ans;
int a[9][9], b[9][9], c[9];
bool vis[9];
inline void dfs(int x){
if (x == n + 1){
bool ok = 1;
for (int i = 1; i <= n; i++){
for (int j = i + 1; j <= n; j++){
if (a[i][j] != b[c[i]][c[j]]){
ok = 0;
}
}
}
if (ok){
ans++;
}
}
for (int i = 1; i <= n; i++){
if (!vis[i]){
vis[i] = 1;
c[x] = i;
dfs(x + 1);
vis[i] = 0;
}
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
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 <= m; i++){
int x, y;
cin >> x >> y;
b[x][y] = b[y][x] = 1;
}
ans = 0;
dfs(1);
if (ans){
cout << "Yes" << '\n';
}
else {
cout << "No" << '\n';
}
}