社区讨论
第九个点!打了点却还是不过!跪辽
P1347[ECNA 2001] 排序参与者 4已保存回复 7
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 7 条
- 当前快照
- 1 份
- 快照标识符
- @mi7yxkk8
- 此快照首次捕获于
- 2025/11/21 05:53 4 个月前
- 此快照最后确认于
- 2025/11/21 05:53 4 个月前
感谢大牛帮助
CPP#include<bits/stdc++.h>
using namespace std;
const int maxn=30;
int n,m;
vector<int> g[maxn];
int d[maxn],ind[maxn],cpyind[maxn];
void topo(int line){
int longest=-1;
memset(d,0,sizeof(d));
memcpy(cpyind,ind,sizeof(ind));
stack<int> st;
queue<int> ansque;
for(int i=1;i<=n;i++)
if(!ind[i])
st.push(i);
while(!st.empty()){
int x=st.top();
st.pop();
longest=max(longest,d[x]);
ansque.push(x);
for(int i=0;i<g[x].size();i++){
int y=g[x][i];
d[y]=max(d[y],d[x]+1);
if(!--cpyind[y])
st.push(y);
}
}
if(ansque.size()<n){
cout<<"Inconsistency found after "<<line<<" relations.";
exit(0);
}
if(longest==n-1){
cout<<"Sorted sequence determined after "<<line<<" relations:";
while(!ansque.empty()){
cout<<char(ansque.front()+'A'-1);
ansque.pop();
}
cout<<'.'<<endl;
exit(0);
}
}
int main(){
cin>>n>>m;
memset(ind,0,sizeof(ind));
char ch1,ch2;
int x,y;
for(int i=1;i<=m;i++){//ch1<ch2
cin>>ch1>>ch2>>ch2;
x=ch1-'A'+1,
y=ch2-'A'+1;
g[x].push_back(y);
ind[y]++;
topo(i);
}
cout<<"Sorted sequence cannot be determined.\n";
return 0;
}
我试着把输出点的cout注释了还是只错第九个点,真的不懂了
回复
共 7 条回复,欢迎继续交流。
正在加载回复...