Saratov State University :: Online Contester


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

::Poll
Are you registered on Codeforces?
Yes
No
What 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;
}


see sub-tree reply to that message


::Login
Forgot password?

::News
22.10.12 - The problems from the Southern Subregional Programming Contest 2012 added to the problemset archive (542 - 553).
22.10.12 - After the start of the contest the statements in PDF will be available by the link.
23.10.11 - The problems from the Southern Subregional Programming Contest 2011 added to the problemset archive (530 - 541).

::Counter

Server time: 2017-11-23 19:30:26Online Contester Team © 2002 - 2016. All rights reserved.