답안 #790751

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
790751 2023-07-23T07:34:29 Z peteza Simurgh (IOI17_simurgh) C++14
51 / 100
87 ms 7500 KB
#include "simurgh.h"
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cassert>
using namespace std;
using pii = pair<int, int>;

int ct, ign;
bool vis[505];
vector<pii> adj[505];
vector<int> times[505];
bool checked[50505];
int inside[50505];

void dfs(int x, vector<int> &to) {
	for(pii e:adj[x]) {
		if(e.first == ign) {
			times[ct].push_back(e.second);
			continue;
		}
		if(vis[e.first]) continue;
		vis[e.first] = 1; 
		to.push_back(e.second);
		dfs(e.first, to);
	}
}

std::vector<int> find_roads(int n, std::vector<int> u, std::vector<int> v) {
	std::vector<int> r;
	int m = u.size();
	for(int i=0;i<m;i++) adj[u[i]].emplace_back(v[i], i), adj[v[i]].emplace_back(u[i], i);
	for(int i=0;i<n;i++) {
		for(int j=0;j<n;j++) times[j].clear();
		//with this node as the main node, generate a spanning tree ignoring this node
		ign = i;
		std::vector<int> toask;
		memset(vis, 0, sizeof vis); vis[i] = 1;
		for(int j=0;j<n;j++) {
			ct = j;
			if(!vis[j]) vis[j] = 1, dfs(j, toask);
		}
		int cq = 0;
		for(int ctime = 0;ctime<n;ctime++) {
			if(times[ctime].empty()) continue;
			for(int ktime=0;ktime<n;ktime++) {
				if(ktime == ctime) continue;
				if(times[ktime].size()) toask.push_back(times[ktime][0]);
			}
			std::vector<int> inans;
			int mx = -1;
			bool once = 0;
			for(int e:times[ctime]) {
				if(checked[e]) {
					if(!inside[e] || once) continue;
					once = 1;
				}
				toask.push_back(e);
				checked[e] = 1;
				assert(toask.size() == n-1 && cq++ <= 30000);
				int res = count_common_roads(toask);
				if(res >= mx) {
					if(res > mx) inans.clear();
					mx = res;
					inans.push_back(e);
				}
				toask.pop_back();
			}
			for(int ktime=0;ktime<n;ktime++) {
				if(ktime == ctime) continue;
				if(times[ktime].size()) toask.pop_back();
			}
			for(int e:inans) inside[e] = 1, r.push_back(e);
		}
	}
	sort(r.begin(), r.end());
	r.resize(unique(r.begin(), r.end())-r.begin());
	return r;
}

/*
4 6
0 1
0 2
0 3
1 2
1 3
2 3
0 1 5
*/

Compilation message

In file included from /usr/include/c++/10/cassert:44,
                 from simurgh.cpp:5:
simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:60:25: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   60 |     assert(toask.size() == n-1 && cq++ <= 30000);
      |            ~~~~~~~~~~~~~^~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB correct
2 Correct 1 ms 340 KB correct
3 Correct 1 ms 340 KB correct
4 Correct 1 ms 340 KB correct
5 Correct 1 ms 212 KB correct
6 Correct 1 ms 340 KB correct
7 Correct 1 ms 212 KB correct
8 Correct 1 ms 340 KB correct
9 Correct 1 ms 328 KB correct
10 Correct 0 ms 340 KB correct
11 Correct 0 ms 212 KB correct
12 Correct 0 ms 212 KB correct
13 Correct 0 ms 212 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB correct
2 Correct 1 ms 340 KB correct
3 Correct 1 ms 340 KB correct
4 Correct 1 ms 340 KB correct
5 Correct 1 ms 212 KB correct
6 Correct 1 ms 340 KB correct
7 Correct 1 ms 212 KB correct
8 Correct 1 ms 340 KB correct
9 Correct 1 ms 328 KB correct
10 Correct 0 ms 340 KB correct
11 Correct 0 ms 212 KB correct
12 Correct 0 ms 212 KB correct
13 Correct 0 ms 212 KB correct
14 Correct 2 ms 336 KB correct
15 Correct 2 ms 340 KB correct
16 Correct 2 ms 332 KB correct
17 Correct 2 ms 340 KB correct
18 Correct 1 ms 340 KB correct
19 Correct 1 ms 340 KB correct
20 Correct 1 ms 328 KB correct
21 Correct 1 ms 332 KB correct
22 Correct 1 ms 336 KB correct
23 Correct 1 ms 340 KB correct
24 Correct 1 ms 340 KB correct
25 Correct 1 ms 340 KB correct
26 Correct 1 ms 328 KB correct
27 Correct 1 ms 340 KB correct
28 Correct 1 ms 340 KB correct
29 Correct 1 ms 340 KB correct
30 Correct 1 ms 340 KB correct
31 Correct 1 ms 340 KB correct
32 Correct 1 ms 340 KB correct
33 Correct 1 ms 340 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB correct
2 Correct 1 ms 340 KB correct
3 Correct 1 ms 340 KB correct
4 Correct 1 ms 340 KB correct
5 Correct 1 ms 212 KB correct
6 Correct 1 ms 340 KB correct
7 Correct 1 ms 212 KB correct
8 Correct 1 ms 340 KB correct
9 Correct 1 ms 328 KB correct
10 Correct 0 ms 340 KB correct
11 Correct 0 ms 212 KB correct
12 Correct 0 ms 212 KB correct
13 Correct 0 ms 212 KB correct
14 Correct 2 ms 336 KB correct
15 Correct 2 ms 340 KB correct
16 Correct 2 ms 332 KB correct
17 Correct 2 ms 340 KB correct
18 Correct 1 ms 340 KB correct
19 Correct 1 ms 340 KB correct
20 Correct 1 ms 328 KB correct
21 Correct 1 ms 332 KB correct
22 Correct 1 ms 336 KB correct
23 Correct 1 ms 340 KB correct
24 Correct 1 ms 340 KB correct
25 Correct 1 ms 340 KB correct
26 Correct 1 ms 328 KB correct
27 Correct 1 ms 340 KB correct
28 Correct 1 ms 340 KB correct
29 Correct 1 ms 340 KB correct
30 Correct 1 ms 340 KB correct
31 Correct 1 ms 340 KB correct
32 Correct 1 ms 340 KB correct
33 Correct 1 ms 340 KB correct
34 Correct 86 ms 1620 KB correct
35 Correct 81 ms 1620 KB correct
36 Correct 57 ms 1436 KB correct
37 Correct 6 ms 420 KB correct
38 Correct 83 ms 1704 KB correct
39 Correct 72 ms 1536 KB correct
40 Correct 57 ms 1368 KB correct
41 Correct 87 ms 1716 KB correct
42 Correct 83 ms 1692 KB correct
43 Correct 46 ms 1108 KB correct
44 Correct 39 ms 852 KB correct
45 Correct 43 ms 852 KB correct
46 Correct 34 ms 868 KB correct
47 Correct 21 ms 596 KB correct
48 Correct 3 ms 340 KB correct
49 Correct 6 ms 340 KB correct
50 Correct 17 ms 604 KB correct
51 Correct 43 ms 988 KB correct
52 Correct 37 ms 916 KB correct
53 Correct 33 ms 860 KB correct
54 Correct 46 ms 1108 KB correct
55 Correct 43 ms 984 KB correct
56 Correct 43 ms 980 KB correct
57 Correct 43 ms 980 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB correct
2 Correct 1 ms 340 KB correct
3 Runtime error 16 ms 7500 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB correct
2 Correct 1 ms 340 KB correct
3 Correct 1 ms 340 KB correct
4 Correct 1 ms 340 KB correct
5 Correct 1 ms 212 KB correct
6 Correct 1 ms 340 KB correct
7 Correct 1 ms 212 KB correct
8 Correct 1 ms 340 KB correct
9 Correct 1 ms 328 KB correct
10 Correct 0 ms 340 KB correct
11 Correct 0 ms 212 KB correct
12 Correct 0 ms 212 KB correct
13 Correct 0 ms 212 KB correct
14 Correct 2 ms 336 KB correct
15 Correct 2 ms 340 KB correct
16 Correct 2 ms 332 KB correct
17 Correct 2 ms 340 KB correct
18 Correct 1 ms 340 KB correct
19 Correct 1 ms 340 KB correct
20 Correct 1 ms 328 KB correct
21 Correct 1 ms 332 KB correct
22 Correct 1 ms 336 KB correct
23 Correct 1 ms 340 KB correct
24 Correct 1 ms 340 KB correct
25 Correct 1 ms 340 KB correct
26 Correct 1 ms 328 KB correct
27 Correct 1 ms 340 KB correct
28 Correct 1 ms 340 KB correct
29 Correct 1 ms 340 KB correct
30 Correct 1 ms 340 KB correct
31 Correct 1 ms 340 KB correct
32 Correct 1 ms 340 KB correct
33 Correct 1 ms 340 KB correct
34 Correct 86 ms 1620 KB correct
35 Correct 81 ms 1620 KB correct
36 Correct 57 ms 1436 KB correct
37 Correct 6 ms 420 KB correct
38 Correct 83 ms 1704 KB correct
39 Correct 72 ms 1536 KB correct
40 Correct 57 ms 1368 KB correct
41 Correct 87 ms 1716 KB correct
42 Correct 83 ms 1692 KB correct
43 Correct 46 ms 1108 KB correct
44 Correct 39 ms 852 KB correct
45 Correct 43 ms 852 KB correct
46 Correct 34 ms 868 KB correct
47 Correct 21 ms 596 KB correct
48 Correct 3 ms 340 KB correct
49 Correct 6 ms 340 KB correct
50 Correct 17 ms 604 KB correct
51 Correct 43 ms 988 KB correct
52 Correct 37 ms 916 KB correct
53 Correct 33 ms 860 KB correct
54 Correct 46 ms 1108 KB correct
55 Correct 43 ms 984 KB correct
56 Correct 43 ms 980 KB correct
57 Correct 43 ms 980 KB correct
58 Correct 1 ms 340 KB correct
59 Correct 1 ms 340 KB correct
60 Runtime error 16 ms 7500 KB Execution killed with signal 11
61 Halted 0 ms 0 KB -