#include <iostream>
#include <cstring>
#include <vector>
using namespace std;
bool isForest;
bool pointTo[101];
bool visited[101];
vector<int> child[101];
int wid[101];
int n, m, maxDepth, maxWidth;
void initialize() {
memset(pointTo, false, sizeof(pointTo));
memset(visited, false, sizeof(visited));
for(int i = 0; i < 101; i++) {
child[i].clear();
}
isForest = true;
maxDepth = 0;
maxWidth = 0;
memset(wid, 0, sizeof(wid));
}
void dfs(int father, int depth) {
visited[father] = true;
maxDepth = (maxDepth > depth ? maxDepth : depth);
wid[depth]++;
maxWidth = (maxWidth > wid[depth] ? maxWidth : wid[depth]);
for(int i = 0; i < child[father].size(); i++) {
dfs(child[father][i], depth + 1);
}
}
int main() {
while(cin >> n >> m && n != 0) {
initialize();
for(int i = 0; i < m; i++) {
int tmp1, tmp2;
cin >> tmp1 >> tmp2;
if(pointTo[tmp2] == true || tmp1 == tmp2) {
isForest = false;
}
else {
child[tmp1].push_back(tmp2);
pointTo[tmp2] = true;
}
}
if(!isForest) {
cout << "INVALID" << endl;
continue;
}
for(int i = 1; i <= n; i++) {
if(!pointTo[i]) {
dfs(i, 0);
}
}
for(int i = 1; i <= n; i++) {
if(!visited[i]) {
isForest = false;
break;
}
}
if(isForest) {
cout << maxDepth << ' ' << maxWidth << endl;
}
else {
cout << "INVALID" << endl;
}
}
return 0;
}
1034. Forest
最新推荐文章于 2025-12-18 17:00:31 发布
部署运行你感兴趣的模型镜像
您可能感兴趣的与本文相关的镜像
ACE-Step
音乐合成
ACE-Step
ACE-Step是由中国团队阶跃星辰(StepFun)与ACE Studio联手打造的开源音乐生成模型。 它拥有3.5B参数量,支持快速高质量生成、强可控性和易于拓展的特点。 最厉害的是,它可以生成多种语言的歌曲,包括但不限于中文、英文、日文等19种语言
1034

被折叠的 条评论
为什么被折叠?



