답안 #393570

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
393570 2021-04-24T03:45:26 Z tinjyu Simurgh (IOI17_simurgh) C++14
51 / 100
411 ms 4896 KB
#include "simurgh.h"
#include <iostream>
#include <vector>
using namespace std;
long long int val[100005],n,road[100005],map[1000005][2],m,cnt,tagv[1000005],tage[1000005],deg[100005],used[100005];
vector<int> r,r1;
int add(int a,int b)
{
	map[cnt][0]=b;
	map[cnt][1]=road[a];
	road[a]=cnt;
	cnt++;
	map[cnt][0]=a;
	map[cnt][1]=road[b];
	road[b]=cnt;
	cnt++;
	return 0;
}
long long int dfs(int x,int y)
{
	//cout<<x<<endl;
	tagv[x]=1;
	long long int g=road[x];
	while(g!=-1)
	{
		long long int now=map[g][0];
		//cout<<x<<" "<<now<<" "<<g<<endl;
		if(used[g/2]==0 && tagv[now]==0 && tage[g/2]==0)
		{
			used[g/2]=1;
			if(now==y)
			{
				r.push_back(g/2);
				return 0;
			}
			int tmp=dfs(now,y);
			if(tmp==0)
			{
				r.push_back(g/2);
				return 0;
			}
			used[g/2]=0;
		}
		g=map[g][1];
	}
	g=road[x];
	while(g!=-1)
	{
		long long int now=map[g][0];
		//cout<<x<<" "<<now<<" "<<g<<endl;
		if(used[g/2]==0 && tagv[now]==0 && tage[g/2]==1)
		{
			used[g/2]=1;
			if(now==y)
			{
				r.push_back(g/2);
				return 0;
			}
			int tmp=dfs(now,y);
			if(tmp==0)
			{
				r.push_back(g/2);
				return 0;
			}
			used[g/2]=0;
		}
		g=map[g][1];
	}
	return 1;
}
int dfs1(int x)
{
	tagv[x]=1;
	long long int g=road[x];
	while(g!=-1)
	{
		long long int now=map[g][0];
		if(tagv[now]==0)
		{
			r1.push_back(g/2);
			dfs1(now);
		}
		g=map[g][1];
	}
	return 0;
}
std::vector<int> find_roads(int N, std::vector<int> u, std::vector<int> v) {
	n=N;
	for(int i=0;i<n;i++)road[i]=-1;
	m=u.size();
	for(int i=0;i<m;i++)
	{
		add(u[i],v[i]);
		//cout<<u[i]<<" "<<v[i]<<" "<<map[i*2][0]<<" "<<map[i*2+1][0]<<endl;
	}
	vector<int> ans;
	vector<int> ask;
	for(int t=0;t<n;t++)
	{
		//cout<<i<<endl;
		long long int g=road[t];
		while(g!=-1)
		{
			long long int now=map[g][0];
			if(tage[g/2]==0)
			{
				for(int j=0;j<m;j++)used[j]=0;
				//cout<<t<<" "<<g/2<<endl;
				for(int j=0;j<n;j++)
				{
					tagv[j]=0;
				}
				r.clear();
				r1.clear();
				ask.clear();
				used[g/2]=1;
				long long int tmp=dfs(now,t);
				//for(int i=0;i<r.size();i++)cout<<r[i]<<" ";
				//cout<<endl;
				if(r.size()==0)
				{
					ans.push_back(g/2);
					tage[g/2]=1;
				}
				else
				{
					r.push_back(g/2);
					for(int i=0;i<n;i++)tagv[i]=0;
					for(int i=0;i<r.size();i++)
					{
						//cout<<r[i]<<" "<<u[r[i]]<<" "<<v[r[i]]<<endl;
						tagv[u[r[i]]]=1;
						tagv[v[r[i]]]=1;
					}
					for(int i=0;i<r.size();i++)
					{
						dfs1(u[r[i]]);
						//cout<<"ok"<<endl;
						dfs1(v[r[i]]);
					}
					long long int mi=9999999;
					long long int c=0;
					for(int i=0;i<r.size();i++)
					{
						ask.clear();
						for(int j=0;j<r.size();j++)
						{
							if(i==j)continue;
							ask.push_back(r[j]);
						}
						for(int j=0;j<r1.size();j++)
						{
							ask.push_back(r1[j]);
						}
						//cout<<"ask"<<endl;
						//for(int j=0;j<ask.size();j++)cout<<ask[j]<<" ";
						//cout<<endl; 
						val[i]=count_common_roads(ask);
						//cout<<val[i]<<endl;0
						mi=min(mi,val[i]);
					}
					for(int i=0;i<r.size();i++)
					{
						if(val[i]!=mi)c=1;
					}
					if(c==1)
					{
						for(int i=0;i<r.size();i++)
						{
							if(val[i]==mi)
							{
									if(tage[r[i]]==0)ans.push_back(r[i]);
							}
							
						}
					}
					for(int i=0;i<r.size();i++)tage[r[i]]=1;
				}
			}
			g=map[g][1];
		}
	}
	//cout<<"ans"<<endl;
	//for(int i=0;i<ans.size();i++)cout<<ans[i]<<" ";
	//cout<<endl; 
	return ans;
}

Compilation message

simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:129:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  129 |      for(int i=0;i<r.size();i++)
      |                  ~^~~~~~~~~
simurgh.cpp:135:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  135 |      for(int i=0;i<r.size();i++)
      |                  ~^~~~~~~~~
simurgh.cpp:143:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  143 |      for(int i=0;i<r.size();i++)
      |                  ~^~~~~~~~~
simurgh.cpp:146:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  146 |       for(int j=0;j<r.size();j++)
      |                   ~^~~~~~~~~
simurgh.cpp:151:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  151 |       for(int j=0;j<r1.size();j++)
      |                   ~^~~~~~~~~~
simurgh.cpp:162:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  162 |      for(int i=0;i<r.size();i++)
      |                  ~^~~~~~~~~
simurgh.cpp:168:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  168 |       for(int i=0;i<r.size();i++)
      |                   ~^~~~~~~~~
simurgh.cpp:177:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  177 |      for(int i=0;i<r.size();i++)tage[r[i]]=1;
      |                  ~^~~~~~~~~
simurgh.cpp:117:19: warning: unused variable 'tmp' [-Wunused-variable]
  117 |     long long int tmp=dfs(now,t);
      |                   ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB correct
2 Correct 1 ms 332 KB correct
3 Correct 1 ms 332 KB correct
4 Correct 1 ms 332 KB correct
5 Correct 1 ms 332 KB correct
6 Correct 1 ms 332 KB correct
7 Correct 1 ms 332 KB correct
8 Correct 1 ms 332 KB correct
9 Correct 1 ms 332 KB correct
10 Correct 1 ms 332 KB correct
11 Correct 1 ms 332 KB correct
12 Correct 1 ms 332 KB correct
13 Correct 1 ms 332 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB correct
2 Correct 1 ms 332 KB correct
3 Correct 1 ms 332 KB correct
4 Correct 1 ms 332 KB correct
5 Correct 1 ms 332 KB correct
6 Correct 1 ms 332 KB correct
7 Correct 1 ms 332 KB correct
8 Correct 1 ms 332 KB correct
9 Correct 1 ms 332 KB correct
10 Correct 1 ms 332 KB correct
11 Correct 1 ms 332 KB correct
12 Correct 1 ms 332 KB correct
13 Correct 1 ms 332 KB correct
14 Correct 4 ms 332 KB correct
15 Correct 4 ms 332 KB correct
16 Correct 4 ms 332 KB correct
17 Correct 3 ms 332 KB correct
18 Correct 1 ms 332 KB correct
19 Correct 3 ms 332 KB correct
20 Correct 3 ms 332 KB correct
21 Correct 3 ms 332 KB correct
22 Correct 2 ms 332 KB correct
23 Correct 3 ms 332 KB correct
24 Correct 2 ms 332 KB correct
25 Correct 1 ms 332 KB correct
26 Correct 2 ms 332 KB correct
27 Correct 2 ms 332 KB correct
28 Correct 1 ms 332 KB correct
29 Correct 1 ms 332 KB correct
30 Correct 2 ms 332 KB correct
31 Correct 2 ms 332 KB correct
32 Correct 2 ms 332 KB correct
33 Correct 2 ms 332 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB correct
2 Correct 1 ms 332 KB correct
3 Correct 1 ms 332 KB correct
4 Correct 1 ms 332 KB correct
5 Correct 1 ms 332 KB correct
6 Correct 1 ms 332 KB correct
7 Correct 1 ms 332 KB correct
8 Correct 1 ms 332 KB correct
9 Correct 1 ms 332 KB correct
10 Correct 1 ms 332 KB correct
11 Correct 1 ms 332 KB correct
12 Correct 1 ms 332 KB correct
13 Correct 1 ms 332 KB correct
14 Correct 4 ms 332 KB correct
15 Correct 4 ms 332 KB correct
16 Correct 4 ms 332 KB correct
17 Correct 3 ms 332 KB correct
18 Correct 1 ms 332 KB correct
19 Correct 3 ms 332 KB correct
20 Correct 3 ms 332 KB correct
21 Correct 3 ms 332 KB correct
22 Correct 2 ms 332 KB correct
23 Correct 3 ms 332 KB correct
24 Correct 2 ms 332 KB correct
25 Correct 1 ms 332 KB correct
26 Correct 2 ms 332 KB correct
27 Correct 2 ms 332 KB correct
28 Correct 1 ms 332 KB correct
29 Correct 1 ms 332 KB correct
30 Correct 2 ms 332 KB correct
31 Correct 2 ms 332 KB correct
32 Correct 2 ms 332 KB correct
33 Correct 2 ms 332 KB correct
34 Correct 411 ms 2344 KB correct
35 Correct 386 ms 2284 KB correct
36 Correct 215 ms 1672 KB correct
37 Correct 13 ms 452 KB correct
38 Correct 401 ms 2268 KB correct
39 Correct 318 ms 2156 KB correct
40 Correct 215 ms 1672 KB correct
41 Correct 403 ms 2372 KB correct
42 Correct 399 ms 2312 KB correct
43 Correct 211 ms 1336 KB correct
44 Correct 163 ms 1276 KB correct
45 Correct 169 ms 1268 KB correct
46 Correct 124 ms 1100 KB correct
47 Correct 50 ms 684 KB correct
48 Correct 7 ms 332 KB correct
49 Correct 14 ms 460 KB correct
50 Correct 52 ms 668 KB correct
51 Correct 180 ms 1264 KB correct
52 Correct 137 ms 1188 KB correct
53 Correct 113 ms 1084 KB correct
54 Correct 176 ms 1308 KB correct
55 Correct 165 ms 1296 KB correct
56 Correct 163 ms 1348 KB correct
57 Correct 188 ms 1460 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB correct
2 Correct 1 ms 332 KB correct
3 Incorrect 292 ms 4896 KB WA in grader: NO
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB correct
2 Correct 1 ms 332 KB correct
3 Correct 1 ms 332 KB correct
4 Correct 1 ms 332 KB correct
5 Correct 1 ms 332 KB correct
6 Correct 1 ms 332 KB correct
7 Correct 1 ms 332 KB correct
8 Correct 1 ms 332 KB correct
9 Correct 1 ms 332 KB correct
10 Correct 1 ms 332 KB correct
11 Correct 1 ms 332 KB correct
12 Correct 1 ms 332 KB correct
13 Correct 1 ms 332 KB correct
14 Correct 4 ms 332 KB correct
15 Correct 4 ms 332 KB correct
16 Correct 4 ms 332 KB correct
17 Correct 3 ms 332 KB correct
18 Correct 1 ms 332 KB correct
19 Correct 3 ms 332 KB correct
20 Correct 3 ms 332 KB correct
21 Correct 3 ms 332 KB correct
22 Correct 2 ms 332 KB correct
23 Correct 3 ms 332 KB correct
24 Correct 2 ms 332 KB correct
25 Correct 1 ms 332 KB correct
26 Correct 2 ms 332 KB correct
27 Correct 2 ms 332 KB correct
28 Correct 1 ms 332 KB correct
29 Correct 1 ms 332 KB correct
30 Correct 2 ms 332 KB correct
31 Correct 2 ms 332 KB correct
32 Correct 2 ms 332 KB correct
33 Correct 2 ms 332 KB correct
34 Correct 411 ms 2344 KB correct
35 Correct 386 ms 2284 KB correct
36 Correct 215 ms 1672 KB correct
37 Correct 13 ms 452 KB correct
38 Correct 401 ms 2268 KB correct
39 Correct 318 ms 2156 KB correct
40 Correct 215 ms 1672 KB correct
41 Correct 403 ms 2372 KB correct
42 Correct 399 ms 2312 KB correct
43 Correct 211 ms 1336 KB correct
44 Correct 163 ms 1276 KB correct
45 Correct 169 ms 1268 KB correct
46 Correct 124 ms 1100 KB correct
47 Correct 50 ms 684 KB correct
48 Correct 7 ms 332 KB correct
49 Correct 14 ms 460 KB correct
50 Correct 52 ms 668 KB correct
51 Correct 180 ms 1264 KB correct
52 Correct 137 ms 1188 KB correct
53 Correct 113 ms 1084 KB correct
54 Correct 176 ms 1308 KB correct
55 Correct 165 ms 1296 KB correct
56 Correct 163 ms 1348 KB correct
57 Correct 188 ms 1460 KB correct
58 Correct 1 ms 332 KB correct
59 Correct 1 ms 332 KB correct
60 Incorrect 292 ms 4896 KB WA in grader: NO
61 Halted 0 ms 0 KB -