12442 - Forwarding Emails

Moderator: Board moderators

beginer
New poster
Posts: 2
Joined: Sat Apr 09, 2016 12:34 pm

Re: 12442 - Forwarding Emails

please igot WA and itied all testcases i found,all give me right answers,this is my code:
#include<stdio.h>
#include<vector>
#include<cstring>
#include<algorithm>
using namespace std;
int n;
#define Max 50100
int dp[Max];
vector< int> visited;
//int dp[100000];
int dfs(int u)
{
visited = 1;
if (dp != 0)
return dp;
dp = 1;
// int ans = 1;
bool cycle = false;
for (int i = 0; i < x; i++)
{
if (visited[k] == 1)
cycle = true;
dp += dfs(k);
dp--;

}
if (cycle)
{
dp = 0, visited = 0;
}
visited[u] = 2;
return dp[u];
}
int main()
{
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
int ts;
scanf("%d", &ts);
for (int ct = 1; ct <= ts; ct++)
{
memset(dp, 0, sizeof dp);
scanf("%d", &n);
visited.clear();
visited.assign(n, 0);
for (int i = 1; i <= n; i++)
{
int x, y;
scanf("%d %d", &x, &y);
x--, y--;
}
int ans = -1, pos = 0;
for (int i = 0; i < n; i++)
{

if (!visited)
{

int x = dfs(i);
if (x>ans)
{
pos = i;
ans = x;
}
}
}
printf("Case %d: %d\n", ct, pos + 1);
//printf("%d", dp[2]);
}
}