记录编号 |
421746 |
评测结果 |
AAAAAAATTT |
题目名称 |
[HAOI 2016]食物链 |
最终得分 |
70 |
用户昵称 |
@@2@ |
是否通过 |
未通过 |
代码语言 |
C++ |
运行时间 |
3.128 s |
提交时间 |
2017-07-08 08:58:12 |
内存使用 |
24.15 MiB |
显示代码纯文本
#include <algorithm>
#include <fstream>
#include <vector>
#include <queue>
#include <cstdlib>
using namespace std;
ifstream cin("chain_2016.in");
ofstream cout("chain_2016.out");
vector<int> e1[1000001]; //1 -> 2
vector<int> e2[1000001]; //2 -> 1
vector<int> end;
bool note[1000001];
int n,m;
queue<int> start;
int ans = 0;
int bfs()
{
start.size();
while(!start.empty())
{
int h = start.front();
start.pop();
if (note[h] == 1)
{
ans++;
/* code */
}
for (int i = 0; i != e1[h].size(); ++i)
{
start.push(e1[h][i]);
}
}
}
int main()
{
int i,j,k,t1,t2;
cin >> n >> m;
for (i = 1; i <= m; ++i)
{
cin >> t1 >> t2;
e1[t1] .push_back(t2);
e2[t2] .push_back(t1);
}
for (i = 1; i <= n; ++i)
{
if(e2[i].size() == 0)
{
if(!(e1[i].size() == 0&&e2[i].size() == 0))
start.push(i);
}
if(e1[i].size() == 0)
{
//end.push_back(i);
note[i] = 1;
}
}
bfs();
cout << ans << endl;
cin.close();
cout.close();
return 0;
}