Submission #3231528


Source Code Expand

//save code
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <set>
using namespace std;

void read(int &x)
{
	char ch=getchar();bool f=0;x=0;
	while(ch>'9'||ch<'0'){if(ch=='-')f=1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-48;ch=getchar();}
	if(f)x=-x;
} 

void read(long long &x)
{
	char ch=getchar();bool f=0;x=0;
	while(ch>'9'||ch<'0'){if(ch=='-')f=1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-48;ch=getchar();}
	if(f)x=-x;
}

struct graph_t
{
	int front,nex;
}graph[201001],graph2[201001];
int tail=1000,tail2=1000;

void addedge(int u,int v)
{
	int tmp=graph[u].nex;
	graph[u].nex=++tail;
	graph[tail].front=v;
	graph[tail].nex=tmp;
}

void addedge2(int u,int v)
{
	int tmp=graph2[u].nex;
	graph2[u].nex=++tail2;
	graph2[tail].front=v;
	graph2[tail].nex=tmp;
}

int vis[1001];
pair<int,int> edge[200001];
int nfinish=0;
int finish[1001];
int nconnect=0;
int connect[1001];
int indegree[1001],outdegree[1001];

void dfs1(int now)
{
	vis[now]=1;
	for(int i=graph[now].nex;i;i=graph[i].nex)
	{
		if(vis[graph[i].front]!=1)
		{
			dfs1(graph[i].front);
		}
	}
	finish[nfinish++]=now;
}

void dfs2(int now)
{
	vis[now]=2;
	connect[now]=nconnect;
	for(int i=graph2[now].nex;i;i=graph2[i].nex)
	{
		if(vis[graph2[i].front]!=2)
		{
			dfs2(graph2[i].front);
		}
	}
}

int main()
{
	int n,m;
	read(n);read(m);
	for(int i=0;i<m;i++)
	{
		int from,to;
		read(from);read(to);
		addedge(from,to);
		addedge(to,from);
		edge[i]=make_pair(from,to);
	}
	for(int i=1;i<=n;i++)
	{
		if(vis[i]!=1)dfs1(i);
	}
	for(int i=nfinish-1;i>=0;i--)
	{
		if(vis[i]!=2)
		{
			nconnect++;
			dfs2(i);
		}
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=graph[i].nex;j;j=graph[j].nex)
		{
			if(connect[j]==connect[graph[j].front])
			{
				outdegree[i]++;
			}
		}
		for(int j=graph2[i].nex;j;j=graph2[j].nex)
		{
			if(connect[j]==connect[graph2[j].front])
			{
				indegree[i]++;
			}
		}
	}
	
/*	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			cout<<vis[i][j]<<" ";
		}
		cout<<endl;
	}*/
	
	return 0;
}
/*
3 3
1 2
1 3
2 3

2 2
1 2
2 1
*/

Submission Info

Submission Time
Task F - Two Faced Edges
User vjudge5
Language C++14 (GCC 5.4.1)
Score 0
Code Size 2069 Byte
Status RE
Exec Time 105 ms
Memory 3712 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 1100
Status
WA × 3
WA × 17
RE × 38
Set Name Test Cases
Sample example_0, example_1, example_2
All bigcycle_0, bigcycle_1, dag_0, dag_1, dag_2, dag_3, dag_4, dag_5, dag_6, dag_7, dagex2_0, dagex2_1, dagex2_2, dagex2_3, dagex_0, dagex_1, dagex_2, dagex_3, example_0, example_1, example_2, maxrand_0, maxrand_1, sep2_0, sep2_1, sep2ex_0, sep2ex_1, sep2ex_2, sep2ex_3, sep2ex_4, sep2ex_5, sep2ex_6, sep2ex_7, sep2ex_8, sep2ex_9, smallrand_0, smallrand_1, smallrand_2, smallrand_3, smallrand_4, smallrand_5, smallrand_6, smallrand_7, smallrand_8, smallrand_9, sparserand_0, sparserand_1, worst2_0, worst2_1, worst2_2, worst2_3, worst_0, worst_1, worst_2, worst_3
Case Name Status Exec Time Memory
bigcycle_0 RE 105 ms 3712 KB
bigcycle_1 RE 105 ms 3712 KB
dag_0 WA 14 ms 3456 KB
dag_1 RE 104 ms 3712 KB
dag_2 WA 14 ms 3584 KB
dag_3 RE 104 ms 3712 KB
dag_4 RE 105 ms 3712 KB
dag_5 RE 104 ms 3712 KB
dag_6 RE 104 ms 3712 KB
dag_7 RE 105 ms 3712 KB
dagex2_0 RE 105 ms 3712 KB
dagex2_1 RE 104 ms 3712 KB
dagex2_2 RE 104 ms 3712 KB
dagex2_3 RE 104 ms 3712 KB
dagex_0 RE 105 ms 3712 KB
dagex_1 RE 105 ms 3712 KB
dagex_2 RE 105 ms 3712 KB
dagex_3 RE 105 ms 3712 KB
example_0 WA 2 ms 2304 KB
example_1 WA 1 ms 2304 KB
example_2 WA 1 ms 2304 KB
maxrand_0 RE 105 ms 3712 KB
maxrand_1 RE 105 ms 3712 KB
sep2_0 RE 105 ms 3712 KB
sep2_1 RE 105 ms 3712 KB
sep2ex_0 RE 105 ms 3712 KB
sep2ex_1 RE 105 ms 3712 KB
sep2ex_2 RE 105 ms 3712 KB
sep2ex_3 RE 104 ms 3712 KB
sep2ex_4 RE 105 ms 3712 KB
sep2ex_5 RE 105 ms 3712 KB
sep2ex_6 RE 105 ms 3712 KB
sep2ex_7 RE 105 ms 3712 KB
sep2ex_8 RE 104 ms 3712 KB
sep2ex_9 RE 105 ms 3712 KB
smallrand_0 WA 2 ms 2304 KB
smallrand_1 WA 2 ms 2304 KB
smallrand_2 WA 2 ms 2304 KB
smallrand_3 WA 1 ms 2304 KB
smallrand_4 WA 1 ms 2304 KB
smallrand_5 WA 1 ms 2304 KB
smallrand_6 WA 1 ms 2304 KB
smallrand_7 WA 1 ms 2304 KB
smallrand_8 WA 1 ms 2304 KB
smallrand_9 WA 1 ms 2304 KB
sparserand_0 WA 2 ms 2432 KB
sparserand_1 WA 2 ms 2432 KB
worst2_0 RE 105 ms 3712 KB
worst2_1 RE 105 ms 3712 KB
worst2_2 RE 105 ms 3712 KB
worst2_3 RE 105 ms 3712 KB
worst_0 RE 105 ms 3712 KB
worst_1 RE 104 ms 3712 KB
worst_2 RE 104 ms 3712 KB
worst_3 RE 105 ms 3712 KB