社区讨论
神秘代码20pts求调玄关
P1347排序参与者 2已保存回复 1
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 1 条
- 当前快照
- 1 份
- 快照标识符
- @mk2pe3zd
- 此快照首次捕获于
- 2026/01/06 22:47 上个月
- 此快照最后确认于
- 2026/01/10 11:45 上个月
我都不知道我写了些什么
CPP#include<bits/stdc++.h>
#define ll long long
#define int register int
#define db double
#define AKIOI ios::sync_with_stdio(false);cin.tie(0),cout.tie(0)
#define AKNOI return 0
#define endl '\n'
#define ch char
using namespace std;
ll n,m,indeg[31],outdeg[31],f[31];
vector<char>v[26];
queue<char>ans;
ll fn(char miu){return miu-'A'+1;}
ch un(long uim){return uim+'A'-1;}
void line_dfs(ll x){
cout<<un(x);
if(v[x].size()==0) return;
ll nxt=v[x][0];
line_dfs(nxt);
}
signed main(){
// AKIOI;
cin>>n>>m;
if(m<n-1){
printf("Sorted sequence cannot be determined.\n");
AKNOI;
}
for(int i=1;i<=m;i++){
char a,op,b;
cin>>a>>op>>b;
v[fn(b)].push_back(a);
indeg[fn(a)]++;
outdeg[fn(b)]++;
ll in0=0,out0=0;
for(int j=1;j<=n;j++){
if(indeg[j]==0) in0++;
if(outdeg[j]==0) out0++;
}
if(in0==0||out0==0){
printf("Inconsistency found after %d relations.\n",i);
AKNOI;
}
if(in0==1&&out0==1){
printf("Sorted sequence determined after %d relations: ",i);
ll st=0;
for(int j=1;j<=n;j++){
if(indeg[j]==0) st=j;
}
line_dfs(st);
AKNOI;
}
// queue<char>q;
// ll k=0;
// while!(q.empty()){
// char now=q.front();
// q.pop();
// //prepare to delete lines
// k++;
// //join into topo
// ll num=0;
// for(auto it:v[now]){
// indeg[it]--;
// if(indeg[it]==0){
// q.push(it);
// num++;
// }
// }
// if(num==0){
// printf("Inconsistency found after %d relations.\n",i);
// AKNOI;
// }
// else if(num>1) continue;
// else ans.push
// }
// if(k!=n){
// printf("Inconsistency found after %d relations.\n",i);
// AKNOI;
// }
}
printf("Sorted sequence cannot be determined.\n");
AKNOI;
}
/*
Sorted sequence determined after x relations: yyy...y.
Inconsistency found after x relations.
Sorted sequence cannot be determined.
*/
回复
共 1 条回复,欢迎继续交流。
正在加载回复...