Submission #117895

# Submission time Handle Problem Language Result Execution time Memory
117895 2019-06-17T10:09:28 Z tinjyu Simurgh (IOI17_simurgh) C++14
13 / 100
1860 ms 3952 KB
#include "simurgh.h"
#include <iostream>
using namespace std;
long long int Na,can,tag[505],map[505][505],r,road[505],tmpans[505][505],s1,s2,anstag[250000],p;
int bfs(int x)
{
	for(int i=0;i<Na;i++)
	{
		if(map[i][x]!=-1 && tag[i]==0 && map[i][x]!=s1 && map[i][x]!=s2)
		{
			//cout<<x<<" "<<i<<"  ";
			tag[i]=1;
			road[p]=map[i][x];
			p++;
			bfs(i);
		}
	}
	return 0;
}
std::vector<int> find_roads(int N, std::vector<int> u, std::vector<int> v) {
	Na=N;
	long long int M=u.size();
	for(int i=0;i<Na;i++)
	{
		for(int j=0;j<Na;j++)map[i][j]=-1;
	}
	for(int i=0;i<M;i++)
	{
		map[u[i]][v[i]]=i;
		map[v[i]][u[i]]=i;
	}	

	for(int i=0;i<Na;i++)
	{
		int c=-1;
		//cout<<i<<endl;
		for(int j=0;j<Na;j++)
		{
			if(map[i][j]!=-1)
			{
				//cout<<j<<endl;
				if(c==-1)
				{
					c=j;
					tmpans[i][0]=1;
					tmpans[i][1]=map[i][j];
				}
				else
				{
					for(int k=0;k<Na;k++)tag[k]=0;
					tag[c]=1;
					tag[i]=1;
					s1=map[i][c];
					s2=map[i][j];
					p=0;
					bfs(c);
					//cout<<endl;
					bfs(i);
					//cout<<endl;
					int tmp=0;
					for(int k=0;k<Na;k++)tmp+=tag[k];
					//cout<<tmp<<endl;
					if(tmp==Na)
					{
						std::vector<int> r(Na - 1);
						for(int k=0;k<Na-1;k++)r[k]=road[k];
						for(int k=0;k<Na;k++)tag[k]=0;
						for(int k=0;k<Na-1;k++)
						{
							int t=r[k];
							//cout<<t<<" "<<u[t]<<" "<<v[t]<<"  ";
							tag[u[t]]++;
							tag[v[t]]++;
						}
						//cout<<endl;
						for(int k=0;k<Na;k++)
						{
							//cout<<tag[k]<<" ";
						}
					//	cout<<endl;
						//cout<<c<<endl;
						r[Na-2]=map[i][c];
						//for(int k=0;k<n-1;k++)cout<<r[k]<<" ";
						//cout<<endl;
						int a= count_common_roads(r);
						r[Na-2]=map[i][j];
						//for(int k=0;k<n-1;k++)cout<<r[k]<<" ";
						//cout<<endl;
						int b= count_common_roads(r);
						//cout<<a<<" "<<b<<endl;
						if(a==b)
						{
							tmpans[i][0]++;
							tmpans[i][tmpans[i][0]]=map[i][j];
						}
						else if(a<b)
						{
							tmpans[i][0]=1;
							tmpans[i][1]=map[i][j];
							c=j;
						}
					}
					else
					{
						tmpans[i][0]++;
						tmpans[i][tmpans[i][0]]=map[i][j];
					}
				}
			}
			//cout<<endl;
			//for(int k=1;k<=tmpans[i][0];k++)cout<<tmpans[i][k]<<" ";
			//cout<<endl;
		}
		//cout<<endl;
	}
	std::vector<int> r(Na - 1);
	//cout<<"can"<<endl;

	int p=0;
	for(int i=0;i<Na;i++)
	{
		//cout<<i<<endl;
		//cout<<tmpans[i][0]<<endl;
		for(int j=1;j<=tmpans[i][0];j++)
		{
			if(anstag[tmpans[i][j]]==0)
			{
				anstag[tmpans[i][j]]=1;
				r[p]=tmpans[i][j];	
				//cout<<r[p]<<" ";
				p++;
			}
		}
		//cout<<endl;
	}
	return r;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB correct
2 Correct 2 ms 384 KB correct
3 Correct 2 ms 384 KB correct
4 Correct 2 ms 384 KB correct
5 Correct 2 ms 384 KB correct
6 Correct 2 ms 384 KB correct
7 Correct 2 ms 384 KB correct
8 Correct 2 ms 384 KB correct
9 Correct 2 ms 384 KB correct
10 Correct 2 ms 384 KB correct
11 Correct 2 ms 384 KB correct
12 Correct 2 ms 384 KB correct
13 Correct 2 ms 384 KB correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB correct
2 Correct 2 ms 384 KB correct
3 Correct 2 ms 384 KB correct
4 Correct 2 ms 384 KB correct
5 Correct 2 ms 384 KB correct
6 Correct 2 ms 384 KB correct
7 Correct 2 ms 384 KB correct
8 Correct 2 ms 384 KB correct
9 Correct 2 ms 384 KB correct
10 Correct 2 ms 384 KB correct
11 Correct 2 ms 384 KB correct
12 Correct 2 ms 384 KB correct
13 Correct 2 ms 384 KB correct
14 Correct 15 ms 768 KB correct
15 Correct 16 ms 768 KB correct
16 Correct 15 ms 768 KB correct
17 Correct 15 ms 768 KB correct
18 Correct 9 ms 768 KB correct
19 Correct 16 ms 768 KB correct
20 Correct 15 ms 796 KB correct
21 Correct 16 ms 768 KB correct
22 Correct 10 ms 768 KB correct
23 Correct 10 ms 768 KB correct
24 Correct 10 ms 768 KB correct
25 Incorrect 2 ms 512 KB WA in grader: NO
26 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB correct
2 Correct 2 ms 384 KB correct
3 Correct 2 ms 384 KB correct
4 Correct 2 ms 384 KB correct
5 Correct 2 ms 384 KB correct
6 Correct 2 ms 384 KB correct
7 Correct 2 ms 384 KB correct
8 Correct 2 ms 384 KB correct
9 Correct 2 ms 384 KB correct
10 Correct 2 ms 384 KB correct
11 Correct 2 ms 384 KB correct
12 Correct 2 ms 384 KB correct
13 Correct 2 ms 384 KB correct
14 Correct 15 ms 768 KB correct
15 Correct 16 ms 768 KB correct
16 Correct 15 ms 768 KB correct
17 Correct 15 ms 768 KB correct
18 Correct 9 ms 768 KB correct
19 Correct 16 ms 768 KB correct
20 Correct 15 ms 796 KB correct
21 Correct 16 ms 768 KB correct
22 Correct 10 ms 768 KB correct
23 Correct 10 ms 768 KB correct
24 Correct 10 ms 768 KB correct
25 Incorrect 2 ms 512 KB WA in grader: NO
26 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB correct
2 Correct 2 ms 384 KB correct
3 Incorrect 1860 ms 3952 KB WA in grader: NO
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 384 KB correct
2 Correct 2 ms 384 KB correct
3 Correct 2 ms 384 KB correct
4 Correct 2 ms 384 KB correct
5 Correct 2 ms 384 KB correct
6 Correct 2 ms 384 KB correct
7 Correct 2 ms 384 KB correct
8 Correct 2 ms 384 KB correct
9 Correct 2 ms 384 KB correct
10 Correct 2 ms 384 KB correct
11 Correct 2 ms 384 KB correct
12 Correct 2 ms 384 KB correct
13 Correct 2 ms 384 KB correct
14 Correct 15 ms 768 KB correct
15 Correct 16 ms 768 KB correct
16 Correct 15 ms 768 KB correct
17 Correct 15 ms 768 KB correct
18 Correct 9 ms 768 KB correct
19 Correct 16 ms 768 KB correct
20 Correct 15 ms 796 KB correct
21 Correct 16 ms 768 KB correct
22 Correct 10 ms 768 KB correct
23 Correct 10 ms 768 KB correct
24 Correct 10 ms 768 KB correct
25 Incorrect 2 ms 512 KB WA in grader: NO
26 Halted 0 ms 0 KB -