### Saratov State University :: Online Contester

::Go
- home
- news
- register
 - update personal info
 - problemset archive
- submit
- status online
- standing
- contests
- virtual contests
- forum
- statistic
- FAQ
- projects

 ::Poll Are you registered on Codeforces?YesNoWhat is it???[results]

::webboard

 WA on Test 2
Author: Maryam G
ID: 066453
Problem: 230
Contest: 0
Date: 2015-12-05 21:43:01

Hi! I get WA on test 2 and can't find the bug. I use TopSort on the graph. Please help. Thanks.

My code:

#include <iostream>
#include <vector>
#include <queue>

using namespace std;

const int MAX_N = 100 + 10;
int deg[MAX_N];
vector <int> graph[MAX_N];

int main()
{
int n, m;
cin >> n >> m;
for (int i = 0; i < m; i++)
{
int a, b;
cin >> a >> b;
a--;
b--;
deg[b]++;
graph[a].push_back(b);
}
queue <int> q;
vector <int> deg0;
for (int i = 0; i < n; i++)
{
if (deg[i] == 0)
{
q.push(i);
deg0.push_back(i);
}
}
while (!q.empty())
{
int v = q.front();
q.pop();
for (int i = 0; i < graph[v].size(); i++)
{
int u = graph[v][i];
deg[u]--;
if (deg[u] == 0)
{
q.push(u);
deg0.push_back(u);
}
}
}
int siz = deg0.size();
if (siz < n)
{
cout << "No solutionn";
return 0;
}
for (int i = 0; i < n; i++)
cout << deg0[i] + 1 << " ";
cout << endl;
return 0;
}