制作伪装网站,北京排名seo,网站恶意刷新,广告设计公司市场专员【codevs2822】爱在心中 2014年1月26日5580题目描述 Description “每个人都拥有一个梦#xff0c;即使彼此不相同#xff0c;能够与你分享#xff0c;无论失败成功都会感动。爱因为在心中#xff0c;平凡而不平庸#xff0c;世界就像迷宫#xff0c;却又让我们此刻相逢O…【codevs2822】爱在心中 2014年1月26日5580 题目描述 Description “每个人都拥有一个梦即使彼此不相同能够与你分享无论失败成功都会感动。爱因为在心中平凡而不平庸世界就像迷宫却又让我们此刻相逢Our Home。” 在爱的国度里有N个人在他们的心中都有着一个爱的名单上面记载着他所爱的人不会出现自爱的情况。爱是具有传递性的即如果A爱BB爱C则A也爱C。如果有这样一部分人他们彼此都相爱则他们就超越了一切的限制用集体的爱化身成为一个爱心天使。现在我们想知道在这个爱的国度里会出现多少爱心天使。而且如果某个爱心天使被其他所有人或爱心天使所爱则请输出这个爱心天使是由哪些人构成的否则输出-1。 输入描述 Input Description 第1行两个数N、M代表爱的国度里有N个人爱的关系有M条。第2到第M1行每行两个数A、B代表A爱B。 输出描述 Output Description 第1行一个数代表爱的国度里有多少爱心天使。第2行如果某个爱心天使被其他所有人和爱心天使所爱则请输出这个爱心天使是由哪些人构成的从小到大排序否则输出-1。 样例输入 Sample Input 样例输入1 6 71 22 33 24 24 55 66 4样例输入2 3 31 22 12 3 样例输出 Sample Output 样例输出1 22 3 样例输出2 1-1 代码 #include cstdio
#include cmath
#include cstring
#include ctime
#include iostream
#include algorithm
#include set
#include vector
#include queue
#include typeinfo
#include map
#includebits/stdc.h
typedef long long ll;
using namespace std;
#define inf 10000000
inline ll read()
{ll x0,f1;char chgetchar();while(ch0||ch9){if(ch-)f-1;chgetchar();}while(ch0ch9){xx*10ch-0;chgetchar();}return x*f;
}
//***************************************************************struct ss
{int u,to,next;
} e[50001];
int out[40001];
int head[50001],vis[50001],dfn[50001],low[50001],belong[50001],hav[50001];
int q[50001],inq[50001];
int t1,bcnt,cnt,n,m,top;
void add(int u,int v)
{e[t].tov;e[t].uu;e[t].nexthead[u];head[u]t;
}
void dfs(int u)
{vis[u]inq[u]1;low[u]dfn[u]cnt;q[top]u;for(int ihead[u]; i; ie[i].next){if(!vis[e[i].to]){dfs(e[i].to);low[u]min(low[u],low[e[i].to]);}else if(inq[e[i].to])low[u]min(low[u],dfn[e[i].to]);}int v-1;if(low[u]dfn[u]){bcnt;while(v!u){vq[top--];inq[v]0;belong[v]bcnt;hav[bcnt];}}
}
void rebuild()
{for(int i1; im; i){if(belong[e[i].u]!belong[e[i].to]){out[belong[e[i].u]];}}
}
void tarjan()
{for(int i1; in; i){if(!vis[i]){dfs(i);}}rebuild();
}
void work()
{int res0;int ans;for(int i1; ibcnt; i){if(out[i]0){ansi;res;}}int bb0;for(int i1;ibcnt;i){if(hav[i]2)bb;}coutbbendl;if(res1){if(hav[ans]!1){int kk0;int hh[50001];for(int i1; in; i){if(belong[i]ans){hh[kk]i;}}for(int i1; ikk; i){printf(%d ,hh[i]);}couthh[kk]endl;}else cout-1endl;}else cout-1endl;
}
int main()
{int u,v;scanf(%d%d,n,m);for(int i1; im; i){scanf(%d%d,u,v);add(u,v);}tarjan();work();return 0;
} 转载于:https://www.cnblogs.com/zxhl/p/4730923.html