답안 #1076183

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1076183 2024-08-26T11:38:46 Z Abito Simurgh (IOI17_simurgh) C++17
30 / 100
2089 ms 31904 KB
#include "simurgh.h"
#include <bits/stdc++.h>
#define pb push_back
#define ask count_common_roads
using namespace std;
const int N=4e4+5;
int par[N],sz[N];
bool in[N],know[N];
map<vector<int>,int> mp;
int getpar(int x){
	if (x==par[x]) return x;
	return par[x]=getpar(par[x]);
}
bool link(int x,int y){
	x=getpar(x);
	y=getpar(y);
	if (x==y) return 0;
	if (sz[x]>sz[y]) swap(x,y);
	sz[y]+=sz[x];
	par[x]=y;
	return 1;
}
std::vector<int> find_roads(int n, std::vector<int> u, std::vector<int> v) {
	int m=u.size();
	for (int i=0;i<m;i++) u[i]++,v[i]++;
	for (int i=1;i<=n;i++) sz[i]=1,par[i]=i;
	vector<int> r;
	for (int i=0;i<m;i++){
		if (link(u[i],v[i])) r.pb(i),in[i]=1;
	}
	int ans=mp[r]=ask(r);
	for (int i=0;i<m && ans<n-1;i++){
		if (!in[i] || know[i]) continue;
		int s=i;
		for (int j=0;j<m;j++){
			if (in[j] || know[j]) continue;
			vector<int> t;
			for (auto x:r) if (x!=i) t.pb(x);
			t.pb(j);
			for (int i=1;i<=n;i++) sz[i]=1,par[i]=i;
			int tree=0;
			for (auto x:t) tree+=link(u[x],v[x]);
			if (tree!=n-1) continue;
			sort(t.begin(),t.end());
			int h;
			if (mp.find(t)==mp.end()){
				mp[t]=ask(t);
			}
			h=mp[t];
			if (h<=ans) continue;
			s=j;
			in[s]=1;
			in[i]=0;
			swap(r,t);
			ans=h;
			break;
		}
		know[i]=1;
		know[s]=1;
	}	
	return r;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB correct
2 Correct 0 ms 348 KB correct
3 Correct 0 ms 348 KB correct
4 Correct 1 ms 348 KB correct
5 Correct 0 ms 348 KB correct
6 Correct 0 ms 348 KB correct
7 Correct 1 ms 348 KB correct
8 Correct 1 ms 348 KB correct
9 Correct 1 ms 348 KB correct
10 Correct 0 ms 348 KB correct
11 Correct 1 ms 348 KB correct
12 Correct 0 ms 348 KB correct
13 Correct 1 ms 348 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB correct
2 Correct 0 ms 348 KB correct
3 Correct 0 ms 348 KB correct
4 Correct 1 ms 348 KB correct
5 Correct 0 ms 348 KB correct
6 Correct 0 ms 348 KB correct
7 Correct 1 ms 348 KB correct
8 Correct 1 ms 348 KB correct
9 Correct 1 ms 348 KB correct
10 Correct 0 ms 348 KB correct
11 Correct 1 ms 348 KB correct
12 Correct 0 ms 348 KB correct
13 Correct 1 ms 348 KB correct
14 Correct 22 ms 1116 KB correct
15 Correct 12 ms 776 KB correct
16 Correct 16 ms 972 KB correct
17 Correct 19 ms 1492 KB correct
18 Correct 6 ms 860 KB correct
19 Correct 20 ms 1680 KB correct
20 Correct 16 ms 1372 KB correct
21 Correct 27 ms 1184 KB correct
22 Correct 1 ms 344 KB correct
23 Correct 1 ms 348 KB correct
24 Correct 0 ms 348 KB correct
25 Correct 0 ms 348 KB correct
26 Correct 1 ms 348 KB correct
27 Correct 1 ms 348 KB correct
28 Correct 1 ms 348 KB correct
29 Correct 0 ms 348 KB correct
30 Correct 1 ms 348 KB correct
31 Correct 0 ms 348 KB correct
32 Correct 0 ms 372 KB correct
33 Correct 1 ms 348 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB correct
2 Correct 0 ms 348 KB correct
3 Correct 0 ms 348 KB correct
4 Correct 1 ms 348 KB correct
5 Correct 0 ms 348 KB correct
6 Correct 0 ms 348 KB correct
7 Correct 1 ms 348 KB correct
8 Correct 1 ms 348 KB correct
9 Correct 1 ms 348 KB correct
10 Correct 0 ms 348 KB correct
11 Correct 1 ms 348 KB correct
12 Correct 0 ms 348 KB correct
13 Correct 1 ms 348 KB correct
14 Correct 22 ms 1116 KB correct
15 Correct 12 ms 776 KB correct
16 Correct 16 ms 972 KB correct
17 Correct 19 ms 1492 KB correct
18 Correct 6 ms 860 KB correct
19 Correct 20 ms 1680 KB correct
20 Correct 16 ms 1372 KB correct
21 Correct 27 ms 1184 KB correct
22 Correct 1 ms 344 KB correct
23 Correct 1 ms 348 KB correct
24 Correct 0 ms 348 KB correct
25 Correct 0 ms 348 KB correct
26 Correct 1 ms 348 KB correct
27 Correct 1 ms 348 KB correct
28 Correct 1 ms 348 KB correct
29 Correct 0 ms 348 KB correct
30 Correct 1 ms 348 KB correct
31 Correct 0 ms 348 KB correct
32 Correct 0 ms 372 KB correct
33 Correct 1 ms 348 KB correct
34 Incorrect 1955 ms 31904 KB WA in grader: NO
35 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB correct
2 Correct 0 ms 348 KB correct
3 Incorrect 2089 ms 21740 KB WA in grader: NO
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB correct
2 Correct 0 ms 348 KB correct
3 Correct 0 ms 348 KB correct
4 Correct 1 ms 348 KB correct
5 Correct 0 ms 348 KB correct
6 Correct 0 ms 348 KB correct
7 Correct 1 ms 348 KB correct
8 Correct 1 ms 348 KB correct
9 Correct 1 ms 348 KB correct
10 Correct 0 ms 348 KB correct
11 Correct 1 ms 348 KB correct
12 Correct 0 ms 348 KB correct
13 Correct 1 ms 348 KB correct
14 Correct 22 ms 1116 KB correct
15 Correct 12 ms 776 KB correct
16 Correct 16 ms 972 KB correct
17 Correct 19 ms 1492 KB correct
18 Correct 6 ms 860 KB correct
19 Correct 20 ms 1680 KB correct
20 Correct 16 ms 1372 KB correct
21 Correct 27 ms 1184 KB correct
22 Correct 1 ms 344 KB correct
23 Correct 1 ms 348 KB correct
24 Correct 0 ms 348 KB correct
25 Correct 0 ms 348 KB correct
26 Correct 1 ms 348 KB correct
27 Correct 1 ms 348 KB correct
28 Correct 1 ms 348 KB correct
29 Correct 0 ms 348 KB correct
30 Correct 1 ms 348 KB correct
31 Correct 0 ms 348 KB correct
32 Correct 0 ms 372 KB correct
33 Correct 1 ms 348 KB correct
34 Incorrect 1955 ms 31904 KB WA in grader: NO
35 Halted 0 ms 0 KB -