当前位置:网站首页>P1347 sorting (TOPO)
P1347 sorting (TOPO)
2022-06-23 04:19:00 【Harris-H】
P1347 Sort (topo)
Deepened topo The understanding of the .
situation 1: It's stable topo, The number of layers is n Chain .
situation 2: Ring , The way to judge the ring is that there are nodes that are not in the queue .
situation 3: Non case 1 and 2, Namely 3.
It is worth noting that the situation 1 Is aimed at n Nodes , situation 2 It is aimed at the current pre - x Ring of nodes .
// Problem: P1347 Sort
// Contest: Luogu
// URL: https://www.luogu.com.cn/problem/P1347
// Memory Limit: 125 MB
// Time Limit: 1000 ms
// Date: 2022-06-22 10:02:38
// --------by Herio--------
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N=1e3+5,M=2e4+5,inf=0x3f3f3f3f,mod=1e9+7;
const int hashmod[4] = {
402653189,805306457,1610612741,998244353};
#define mst(a,b) memset(a,b,sizeof a)
#define db double
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define x first
#define y second
#define pb emplace_back
#define SZ(a) (int)a.size()
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define per(i,a,b) for(int i=a;i>=b;--i)
#define IOS ios::sync_with_stdio(false),cin.tie(nullptr)
void Print(int *a,int n){
for(int i=1;i<n;i++)
printf("%d ",a[i]);
printf("%d\n",a[n]);
}
template <typename T> //x=max(x,y) x=min(x,y)
void cmx(T &x,T y){
if(x<y) x=y;
}
template <typename T>
void cmn(T &x,T y){
if(x>y) x=y;
}
vector<int>e[N];
int _in[N],in[N];
bitset<N>vis;
int d[26];
int n,m;
void topo(int r){
queue<int>q;
memcpy(in,_in,sizeof in);
int cnt = 0;
vector<int>ans;
mst(d,0);
int _n = 0;
for(int i=0;i<26;i++) if(vis[i]) _n++;
for(int i=0;i<26;i++)
if(vis[i] && !in[i]){
q.push(i);
cnt++;
}
int mx = 0;
while(!q.empty()){
int u = q.front();q.pop();
ans.pb(u);
cmx(mx,d[u]);
for(int v:e[u]){
if(!--in[v]){
q.push(v);
d[v] = d[u] + 1;
cnt++;
}
}
}
if(mx==n-1){
printf("Sorted sequence determined after %d relations: ",r);
for(int x:ans) printf("%c",x+'A');
puts(".");
exit(0);
}
else if(cnt<_n){
printf("Inconsistency found after %d relations.",r);
exit(0);
}
}
int main(){
scanf("%d%d",&n,&m);
for(int i=1;i<=m;i++){
string s;
cin>>s;
e[s[0]-'A'].pb(s[2]-'A');
vis[s[0]-'A'] = vis[s[2]-'A'] = true;
_in[s[2]-'A']++;
topo(i);
}
puts("Sorted sequence cannot be determined.");
return 0;
}
边栏推荐
- D overloading nested functions
- 直接插入排序
- How the innovative use of adobe international certification 𞓜 3D changes the entire industry
- 直接插入排序
- Weekly Postgres world news 2022w02
- Tcapulusdb Jun · industry news collection (V)
- 两招提升硬盘存储数据的写入效率
- 基于FPGA的VGA协议实现
- 怎样能在小程序中实现视频通话及互动直播功能?
- Review the SQL row column conversion, and the performance has been improved
猜你喜欢

Centos7 installing MySQL and configuring InnoDB_ ruby

mysql如何删除表的一行数据

Review the SQL row column conversion, and the performance has been improved

node+express如何操作cookie

Efficient remote office experience | community essay solicitation

移动端城市列表排序js插件vercitylist.js

【机器学习】 吴恩达机器学习作业 ex2逻辑回归 Matlab实现

直接插入排序

svg d3.js生成tree树状图

粒子动画背景登录页面particles.js
随机推荐
linux下的开源数据库是什么
京东云分布式数据库StarDB荣获中国信通院 “稳定性实践先锋”
深度学习 TensorFlow入门
顺序表查找
Form development mode
Static lookup tables and static lookup tables
Mysql, field problem
mysql存储引擎之Myisam和Innodb的区别
无线网络安全的12个优秀实践
QMainWindow
[binary tree] 993 Cousins in Binary Tree
Questions about SQL statements
redisTemplate和cacheManager操作redis有什么不同
Similar to RZ / SZ, trzsz supporting TMUX has released a new version
What is the potential of dmail based on Web3.0? First round financing of $10 million?
浅析2022年物联网现状
For patch rollback, please check the cbpersistent log
如何处理大体积 XLSX/CSV/TXT 文件?
Full analysis of embedded software testing tool tpt18 update
1-1 introduction to VMWare