当前位置:网站首页>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;
}
边栏推荐
- What are the answers about older bloggers?
- 【暑期每日一题】洛谷 P4413 [COCI2006-2007#2] R2
- A long article --- in-depth understanding of synchronized
- Logback log level introduction
- Use of gcc/g++
- How does MySQL convert rows to columns?
- cdc source能读完MySqlSnapshotSplit 就退出嘛
- Introduction to logback filter
- log4j Layout简介说明
- RoBERTa:A Robustly Optimized BERT Pretraining Approach
猜你喜欢

MySQL uses the client and select methods to view the summary of blob type fields

多线程购物

Prometheus与Grafana

stm32 操作W25Q256 W25Q16 spi flash

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

JS day 4 process control (if statement and switch statement)

thinkphp6 实现数据库备份

Prometheus and grafana

美智光电IPO被终止:年营收9.26亿 何享健为实控人

【MYSQL】-【子查询】
随机推荐
LevelFilter简介说明
Dilworth 定理
logback appender简介说明
UPC 小C的王者峡谷
Log4qt memory leak, use of heob memory detection tool
Description of rollingfileappender attribute in logback
电子元器件贸易企业如何借助ERP系统,解决仓库管理难题?
I, 28, a tester, was ruthlessly dismissed in October: I want to remind people who are still learning to test
mysql 单表最多能存多少数据?
Getting started with JDBC
STM32 operation w25q256 w25q16 SPI flash
反射reflect
@RequestMapping 用法详解
NFT 的 10 种实际用途
Scala 高阶(九):Scala中的模式匹配
RoBERTa:A Robustly Optimized BERT Pretraining Approach
国内数字藏品的乱象与未来
蓝桥杯A组选数异或
【暑期每日一题】洛谷 P6320 [COCI2006-2007#4] SIBICE
mysql 使用 DATE_FORMAT(date,'%Y-%m')