当前位置:网站首页>Popular cow G
Popular cow G
2022-07-29 07:33:00 【A little Yu】
Background
The test data has been fixed .
Title Description
Every cow dreams of being a star in the cowshed . The cow that all cows like is a star cow . All cows are narcissists , Every cow always likes its own . Between cows “ like ” It can be transmitted —— If AA like BB,BB like CC, that AA I also like CC. It's in the bullpen NN A cow , Given some of the relationships between cows , Please figure out how many cows can be stars .
Input format
first line : Two integers separated by spaces :NN and MM.
Next MM That's ok : Two integers separated by spaces on each line :AA and BB, Express AA like BB.
Output format
A single integer in a row , The number of star cows .
I/o sample
Input #1 Copy
3 3 1 2 2 1 2 3
Output #1 Copy
1
explain / Tips
Only 33 Cow number one can be a star .
【 Data range 】
about 10\%10% The data of ,N\le20N≤20,M\le50M≤50.
about 30\%30% The data of ,N\le10^3N≤103,M\le2\times 10^4M≤2×104.
about 70\%70% The data of ,N\le5\times 10^3N≤5×103,M\le5\times 10^4M≤5×104.
about 100\%100% The data of ,1\le N\le10^41≤N≤104,1\le M\le5\times 10^41≤M≤5×104.
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+5;
vector<int>G[N];
int n,m;
int sum,low[N],ins[N],dfn[N],col,a,cmpi[N],F[N],cmp[N];
bool D[N];
stack<int>s;
int find()
{
int ans=0;
for(int i=1; i<=a; i++)
{
for(int j=0; j<G[F[i]].size(); j++) // List all adjacent points of this point
{
if(!D[G[F[i]][j]])
{
ans++; // If the adjacent point of this point is not in a strong connection with it , Then we will find that his weight has a degree
}
}
}
return ans;
}// Find out the degree of a group of strongly connected components
void tarjan(int x)
{
sum++;
dfn[x]=low[x]=sum;
s.push(x);
ins[x]=1;
for(int i=0; i<G[x].size(); i++)
{
if(ins[G[x][i]]==0)
{
tarjan(G[x][i]);
low[x]=min(low[x],low[G[x][i]]);
}
else if(ins[G[x][i]]==1)
low[x]=min(low[x],dfn[G[x][i]]);
}
if(dfn[x]==low[x])
{
col++;
int node;
do
{
node=s.top();
s.pop();
ins[node]=-1;
D[node]=true;
F[++a]=node;
cmpi[col]++;
}
while(node!=x);
cmp[col]=find();
a=0;
memset(D,false,sizeof D);
}
return ;
}
int main()
{
cin>>n>>m;
for(int i=1; i<=m; i++)
{
int a,b;
cin>>a>>b;
G[a].push_back(b);
}
for(int i=1; i<=n; i++)
{
if(!dfn[i])tarjan(i);
}
int c=0,ans;
for(int i=1; i<=col; i++)
{
if(!cmp[i])
{
c++,ans=i;
}
}
if(c==1)
{
cout<<cmpi[ans];
}
else
{
cout<<0;
}
return 0;
}
边栏推荐
- Female graduate students do "mind mapping" and quarrel with their boyfriend! Netizen: the "king of infighting" in the quarrel
- 我,28岁,测试员,10月无情被辞:想给还在学测试 的人提个醒......
- 09 bloom filter
- 【暑期每日一题】洛谷 P6320 [COCI2006-2007#4] SIBICE
- 一篇长文---深入理解synchronized
- MapReduce各阶段步骤
- [summer daily question] Luogu p6320 [coci2006-2007 4] sibice
- cs61abc分享会(六)程序的输入输出详解 - 标准输入输出,文件,设备,EOF,命令行参数
- Use of gcc/g++
- 电子元器件贸易企业如何借助ERP系统,解决仓库管理难题?
猜你喜欢

Meizhi optoelectronics' IPO was terminated: annual revenue of 926million he Xiangjian was the actual controller

QT连接两个qslite数据库报错QSqlQuery::exec: database not open

QT基础第二天(2)qt基础部件:按钮类,布局类,输出类,输入类,容器等个别举例

Getting started with JDBC

Meeting notice of OA project (Query & whether to attend the meeting & feedback details)

OA项目之会议通知(查询&是否参会&反馈详情)

Use custom annotations to verify the size of the list

【深度学习】数据准备-pytorch自定义图像分割类数据集加载

梳理市面上的2大NFT定价范式和4种解决方案

Sqlmap(SQL注入自动化工具)
随机推荐
Scala 高阶(十):Scala中的异常处理
leetcode力扣经典问题——4.寻找两个正序数组的中位数
mysql 单表最多能存多少数据?
【Unity实战100例】Unity万能答题系统之单选多选判断题全部通用
能在SQL 语句中 指定 内存参数吗?
do end用法的妙处
我想问一下,我flink作业是以upsert-kafka的方式写入数据的,但是我在mysql里面去更
【暑期每日一题】洛谷 P6320 [COCI2006-2007#4] SIBICE
【无标题】格式保存
logback appender简介说明
cdc source能读完MySqlSnapshotSplit 就退出嘛
Vue router route cache
[summer daily question] Luogu p6461 [coci2006-2007 5] trik
状态机dp(简单版)
Segger's hardware anomaly analysis
Android面试题 | 怎么写一个又好又快的日志库?
Use of gcc/g++
log4j Layout简介说明
[summer daily question] Luogu p6336 [coci2007-2008 2] bijele
JS break and continue and return keywords