답안 #73287

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
73287 2018-08-28T06:40:56 Z Sa1378 Simurgh (IOI17_simurgh) C++17
51 / 100
218 ms 7092 KB
#include "simurgh.h"
#include <bits/stdc++.h>
using namespace std;
#define N ((int)510)
#define M ((int)151*1000)

int n,m;
pair <int,int> ed[M];
vector <int> e[N],edges,ed_id;
bool ans[M],mark[N];

void dfs(int x,int v)
{
	mark[x]=1;
	for(auto u:e[v])
		if(ed[u].first+ed[u].second-v==x)
		{
			ed_id.push_back(u);
			break;
		}
	for(auto u:e[x])
	{
		int p=ed[u].first+ed[u].second-x;
		if(!mark[p])
		{
			edges.push_back(u);
			dfs(p,v);
		}
	}
}

vector<int> find_roads(int n2,vector<int> u,vector<int> v)
{
	n=n2;m=u.size();
	for(int i=0;i<m;i++)
		ed[i]={v[i],u[i]},
		e[v[i]].push_back(i),
		e[u[i]].push_back(i);
	for(int i=0;i<n-1;i++)
	{
		memset(mark,0,sizeof mark);
		mark[i]=1;
		edges.clear();
		vector <vector <int> > groups;
		for(int j=0;j<n;j++)
			if(!mark[j])
			{
				ed_id.clear();
				dfs(j,i);
				groups.push_back(ed_id);
			}
		for(auto vec:groups)
		{
			vector <int> ex_ed;ex_ed=edges;
			for(auto vec2:groups)
				if(vec!=vec2)
					edges.push_back(vec2[0]);
			vector <int> res;
			for(auto u:vec)
			{
				if(ed[u].first+ed[u].second-i<i)
				{
					res.push_back(N);
					continue;
				}
				edges.push_back(u);
				res.push_back(count_common_roads(edges));
				edges.pop_back();
			}
			int mini=N;
			for(auto u:res)mini=min(mini,u);
			if(mini==N)
			{
				edges=ex_ed;
				continue;
			}
			bool flg=0;
			for(auto u:res)
				if(u==mini+1)
					flg=1;
			if(flg)
			{
				for(int j=0;j<vec.size();j++)
					if(res[j]==mini+1)
						ans[vec[j]]=1;
				edges=ex_ed;
				continue;
			}
			flg=0;
			for(int j=0;j<vec.size();j++)
				if(res[j]==N && ans[vec[j]])
					flg=1;
			if(!flg)
			{
				for(int j=0;j<vec.size();j++)
					if(res[j]!=N)
						ans[vec[j]]=1;
				edges=ex_ed;
				continue;
			}
			for(int j=0;j<vec.size();j++)
				if(res[j]==N && ans[vec[j]])
				{
					edges.push_back(vec[j]);
					int ex=count_common_roads(edges);
					edges.pop_back();
					if(ex==mini)
					{
						for(int k=0;k<vec.size();k++)
							if(res[k]==mini)
								ans[vec[k]]=1;
					}
					break;
				}
			edges=ex_ed;
		}
	}
	vector <int> res;
	for(int i=0;i<m;i++)
		if(ans[i])
			res.push_back(i);
	return res;
}

Compilation message

simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:83:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int j=0;j<vec.size();j++)
                 ~^~~~~~~~~~~
simurgh.cpp:90:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(int j=0;j<vec.size();j++)
                ~^~~~~~~~~~~
simurgh.cpp:95:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int j=0;j<vec.size();j++)
                 ~^~~~~~~~~~~
simurgh.cpp:101:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(int j=0;j<vec.size();j++)
                ~^~~~~~~~~~~
simurgh.cpp:109:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
       for(int k=0;k<vec.size();k++)
                   ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 380 KB correct
2 Correct 3 ms 460 KB correct
3 Correct 3 ms 460 KB correct
4 Correct 3 ms 572 KB correct
5 Correct 3 ms 572 KB correct
6 Correct 3 ms 572 KB correct
7 Correct 2 ms 572 KB correct
8 Correct 3 ms 572 KB correct
9 Correct 3 ms 572 KB correct
10 Correct 3 ms 620 KB correct
11 Correct 4 ms 648 KB correct
12 Correct 3 ms 652 KB correct
13 Correct 2 ms 656 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 380 KB correct
2 Correct 3 ms 460 KB correct
3 Correct 3 ms 460 KB correct
4 Correct 3 ms 572 KB correct
5 Correct 3 ms 572 KB correct
6 Correct 3 ms 572 KB correct
7 Correct 2 ms 572 KB correct
8 Correct 3 ms 572 KB correct
9 Correct 3 ms 572 KB correct
10 Correct 3 ms 620 KB correct
11 Correct 4 ms 648 KB correct
12 Correct 3 ms 652 KB correct
13 Correct 2 ms 656 KB correct
14 Correct 4 ms 768 KB correct
15 Correct 5 ms 768 KB correct
16 Correct 5 ms 768 KB correct
17 Correct 6 ms 768 KB correct
18 Correct 4 ms 768 KB correct
19 Correct 4 ms 780 KB correct
20 Correct 5 ms 780 KB correct
21 Correct 4 ms 832 KB correct
22 Correct 6 ms 836 KB correct
23 Correct 4 ms 840 KB correct
24 Correct 4 ms 960 KB correct
25 Correct 4 ms 960 KB correct
26 Correct 4 ms 960 KB correct
27 Correct 6 ms 960 KB correct
28 Correct 4 ms 960 KB correct
29 Correct 4 ms 960 KB correct
30 Correct 4 ms 960 KB correct
31 Correct 4 ms 960 KB correct
32 Correct 3 ms 960 KB correct
33 Correct 4 ms 960 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 380 KB correct
2 Correct 3 ms 460 KB correct
3 Correct 3 ms 460 KB correct
4 Correct 3 ms 572 KB correct
5 Correct 3 ms 572 KB correct
6 Correct 3 ms 572 KB correct
7 Correct 2 ms 572 KB correct
8 Correct 3 ms 572 KB correct
9 Correct 3 ms 572 KB correct
10 Correct 3 ms 620 KB correct
11 Correct 4 ms 648 KB correct
12 Correct 3 ms 652 KB correct
13 Correct 2 ms 656 KB correct
14 Correct 4 ms 768 KB correct
15 Correct 5 ms 768 KB correct
16 Correct 5 ms 768 KB correct
17 Correct 6 ms 768 KB correct
18 Correct 4 ms 768 KB correct
19 Correct 4 ms 780 KB correct
20 Correct 5 ms 780 KB correct
21 Correct 4 ms 832 KB correct
22 Correct 6 ms 836 KB correct
23 Correct 4 ms 840 KB correct
24 Correct 4 ms 960 KB correct
25 Correct 4 ms 960 KB correct
26 Correct 4 ms 960 KB correct
27 Correct 6 ms 960 KB correct
28 Correct 4 ms 960 KB correct
29 Correct 4 ms 960 KB correct
30 Correct 4 ms 960 KB correct
31 Correct 4 ms 960 KB correct
32 Correct 3 ms 960 KB correct
33 Correct 4 ms 960 KB correct
34 Correct 218 ms 2076 KB correct
35 Correct 185 ms 2272 KB correct
36 Correct 129 ms 2272 KB correct
37 Correct 13 ms 2272 KB correct
38 Correct 180 ms 2616 KB correct
39 Correct 143 ms 2692 KB correct
40 Correct 108 ms 2692 KB correct
41 Correct 158 ms 3124 KB correct
42 Correct 173 ms 3324 KB correct
43 Correct 99 ms 3324 KB correct
44 Correct 83 ms 3324 KB correct
45 Correct 99 ms 3324 KB correct
46 Correct 79 ms 3324 KB correct
47 Correct 33 ms 3324 KB correct
48 Correct 6 ms 3324 KB correct
49 Correct 11 ms 3324 KB correct
50 Correct 36 ms 3324 KB correct
51 Correct 101 ms 3348 KB correct
52 Correct 75 ms 3448 KB correct
53 Correct 65 ms 3448 KB correct
54 Correct 88 ms 3740 KB correct
55 Correct 95 ms 3744 KB correct
56 Correct 87 ms 3912 KB correct
57 Correct 86 ms 3936 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3936 KB correct
2 Correct 2 ms 3936 KB correct
3 Incorrect 160 ms 7092 KB WA in grader: NO
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 380 KB correct
2 Correct 3 ms 460 KB correct
3 Correct 3 ms 460 KB correct
4 Correct 3 ms 572 KB correct
5 Correct 3 ms 572 KB correct
6 Correct 3 ms 572 KB correct
7 Correct 2 ms 572 KB correct
8 Correct 3 ms 572 KB correct
9 Correct 3 ms 572 KB correct
10 Correct 3 ms 620 KB correct
11 Correct 4 ms 648 KB correct
12 Correct 3 ms 652 KB correct
13 Correct 2 ms 656 KB correct
14 Correct 4 ms 768 KB correct
15 Correct 5 ms 768 KB correct
16 Correct 5 ms 768 KB correct
17 Correct 6 ms 768 KB correct
18 Correct 4 ms 768 KB correct
19 Correct 4 ms 780 KB correct
20 Correct 5 ms 780 KB correct
21 Correct 4 ms 832 KB correct
22 Correct 6 ms 836 KB correct
23 Correct 4 ms 840 KB correct
24 Correct 4 ms 960 KB correct
25 Correct 4 ms 960 KB correct
26 Correct 4 ms 960 KB correct
27 Correct 6 ms 960 KB correct
28 Correct 4 ms 960 KB correct
29 Correct 4 ms 960 KB correct
30 Correct 4 ms 960 KB correct
31 Correct 4 ms 960 KB correct
32 Correct 3 ms 960 KB correct
33 Correct 4 ms 960 KB correct
34 Correct 218 ms 2076 KB correct
35 Correct 185 ms 2272 KB correct
36 Correct 129 ms 2272 KB correct
37 Correct 13 ms 2272 KB correct
38 Correct 180 ms 2616 KB correct
39 Correct 143 ms 2692 KB correct
40 Correct 108 ms 2692 KB correct
41 Correct 158 ms 3124 KB correct
42 Correct 173 ms 3324 KB correct
43 Correct 99 ms 3324 KB correct
44 Correct 83 ms 3324 KB correct
45 Correct 99 ms 3324 KB correct
46 Correct 79 ms 3324 KB correct
47 Correct 33 ms 3324 KB correct
48 Correct 6 ms 3324 KB correct
49 Correct 11 ms 3324 KB correct
50 Correct 36 ms 3324 KB correct
51 Correct 101 ms 3348 KB correct
52 Correct 75 ms 3448 KB correct
53 Correct 65 ms 3448 KB correct
54 Correct 88 ms 3740 KB correct
55 Correct 95 ms 3744 KB correct
56 Correct 87 ms 3912 KB correct
57 Correct 86 ms 3936 KB correct
58 Correct 2 ms 3936 KB correct
59 Correct 2 ms 3936 KB correct
60 Incorrect 160 ms 7092 KB WA in grader: NO
61 Halted 0 ms 0 KB -