记录编号 |
388606 |
评测结果 |
AAAAA |
题目名称 |
通讯问题 |
最终得分 |
100 |
用户昵称 |
JustWB |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.002 s |
提交时间 |
2017-03-29 15:15:07 |
内存使用 |
0.32 MiB |
显示代码纯文本
- #include<iostream>
- #include<cstdio>
- #include<cstring>
- #include<queue>
- #include<vector>
- #include<stack>
- #include<algorithm>
- using namespace std;
- int n,a,b,all;
- int dfn[101],low[101];
- bool pan[101];
- vector<int> tx[101];
- stack<int> tar;
- struct ans
- {
- int min;
- priority_queue<int> q;
- ans(){min=0x7ffff;}
- bool operator < (const ans A)const
- {
- return min<A.min;
- }
- }sum[101];
- void tj(int now,int df)
- {
- dfn[now]=df;
- low[now]=dfn[now];
- tar.push(now);
- pan[now]=1;
- for(int i=0;i<tx[now].size();i++)
- {
- int nt=tx[now][i];
- if(!pan[nt])
- {
- tj(nt,df+1);
- }
- low[now]=min(low[now],low[nt]);
- }
- if(dfn[now]==low[now])
- {
- all++;
- while(tar.top()!=now)
- {
- if(tar.top()<sum[all].min)sum[all].min=tar.top();
- sum[all].q.push(-tar.top());
- tar.pop();
- }
- if(tar.top()<sum[all].min)sum[all].min=tar.top();
- sum[all].q.push(-tar.top());
- tar.pop();
- }
- }
- int main()
- {
- freopen("jdltt.in","r",stdin);
- freopen("jdltt.out","w",stdout);
- scanf("%d",&n);
- while(scanf("%d%d",&a,&b)!=EOF)
- {
- tx[a].push_back(b);
- }
- for(int i=1;i<=n;i++)
- {
- if(pan[i])continue;
- tj(i,1);
- }
- printf("%d\n",all);
- sort(sum+1,sum+(all+1));
- for(int i=1;i<=all;i++)
- {
- while(!sum[i].q.empty())
- {
- printf("%d ",-sum[i].q.top());
- sum[i].q.pop();
- }
- printf("\n");
- }
- return 0;
- }