답안 #128382

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
128382 2019-07-10T20:31:20 Z DanerZein Simurgh (IOI17_simurgh) C++14
13 / 100
30 ms 392 KB
#include "simurgh.h"
#include<bits/stdc++.h>
using namespace std;
typedef vector<int>vi;
vector<vi> G;
int pa[22];
int findset(int u){
    if(pa[u]==u) return u;
    else return pa[u]=findset(pa[u]);
}
bool unionset(int u,int v){
    u=findset(u);
    v=findset(v);
    if(u==v){
        return false;
    }
    else{
        pa[u]=v;
        return true;
    }
}
std::vector<int> find_roads(int n, std::vector<int> u, std::vector<int> v) {
	std::vector<int> r;
	int t=u.size();
	for(int i=0;i<(1<<t);i++){
        if(__builtin_popcount(i)==n-1){
            for(int j=0;j<n;j++){
                pa[j]=j;
            }
            bool sw=0;
            vector<int>rg;
            for(int j=0;j<t;j++){
                if(i&(1<<j)){
                    rg.push_back(j);
                    //cout<<j<<endl;
                    if(!unionset(u[j],v[j])){
                        sw=1;
                        break;
                    }
                }
                //cout<<j<<endl;
            }
           // cout<<"i: "<<i<<" sw: "<<sw<<endl;
            if(sw==0){
               // cout<<"a"<<endl;
               /* for(int j=0;j<rg.size();j++){
                    cout<<rg[j]<<" ";
                }
                cout<<endl;*/
                if(count_common_roads(rg)==n-1){
                    return rg;
                }
            }
        }
	}
}
/*
static int MAXQ = 30000;

static int n, m, q = 0;
static vector<int> u, v;
static vector<bool> goal;

static void wrong_answer() {
	printf("NO\n");
	exit(0);
}

static bool is_valid(const vector<int>& r) {
	if(int(r.size()) != n - 1)
		return false;

	for(int i = 0; i < n - 1; i++)
		if (r[i] < 0 || r[i] >= m)
			return false;

	return true;
}

static int _count_common_roads_internal(const vector<int>& r) {
	if(!is_valid(r))
		wrong_answer();

	int common = 0;
	for(int i = 0; i < n - 1; i++) {
		bool is_common = goal[r[i]];
		if (is_common)
			common++;
	}

	return common;
}

int count_common_roads(const vector<int>& r) {
	q++;
	if(q > MAXQ)
		wrong_answer();

	return _count_common_roads_internal(r);
}

int main() {
	assert(2 == scanf("%d %d", &n, &m));

	u.resize(m);
	v.resize(m);

	for(int i = 0; i < m; i++)
		assert(2 == scanf("%d %d", &u[i], &v[i]));

	goal.resize(m, false);

	for(int i = 0; i < n - 1; i++) {
		int id;
		assert(1 == scanf("%d", &id));
		goal[id] = true;
	}

	vector<int> res = find_roads(n, u, v);

	if(_count_common_roads_internal(res) != n - 1)
		wrong_answer();

	printf("YES\n");

	return 0;
}
*/

Compilation message

simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:56:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 256 KB correct
2 Correct 27 ms 376 KB correct
3 Correct 30 ms 376 KB correct
4 Correct 3 ms 376 KB correct
5 Correct 3 ms 256 KB correct
6 Correct 5 ms 380 KB correct
7 Correct 2 ms 276 KB correct
8 Correct 2 ms 256 KB correct
9 Correct 2 ms 376 KB correct
10 Correct 3 ms 392 KB correct
11 Correct 2 ms 376 KB correct
12 Correct 3 ms 256 KB correct
13 Correct 15 ms 364 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 256 KB correct
2 Correct 27 ms 376 KB correct
3 Correct 30 ms 376 KB correct
4 Correct 3 ms 376 KB correct
5 Correct 3 ms 256 KB correct
6 Correct 5 ms 380 KB correct
7 Correct 2 ms 276 KB correct
8 Correct 2 ms 256 KB correct
9 Correct 2 ms 376 KB correct
10 Correct 3 ms 392 KB correct
11 Correct 2 ms 376 KB correct
12 Correct 3 ms 256 KB correct
13 Correct 15 ms 364 KB correct
14 Incorrect 3 ms 376 KB WA in grader: NO
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 256 KB correct
2 Correct 27 ms 376 KB correct
3 Correct 30 ms 376 KB correct
4 Correct 3 ms 376 KB correct
5 Correct 3 ms 256 KB correct
6 Correct 5 ms 380 KB correct
7 Correct 2 ms 276 KB correct
8 Correct 2 ms 256 KB correct
9 Correct 2 ms 376 KB correct
10 Correct 3 ms 392 KB correct
11 Correct 2 ms 376 KB correct
12 Correct 3 ms 256 KB correct
13 Correct 15 ms 364 KB correct
14 Incorrect 3 ms 376 KB WA in grader: NO
15 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB correct
2 Incorrect 2 ms 256 KB WA in grader: NO
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 256 KB correct
2 Correct 27 ms 376 KB correct
3 Correct 30 ms 376 KB correct
4 Correct 3 ms 376 KB correct
5 Correct 3 ms 256 KB correct
6 Correct 5 ms 380 KB correct
7 Correct 2 ms 276 KB correct
8 Correct 2 ms 256 KB correct
9 Correct 2 ms 376 KB correct
10 Correct 3 ms 392 KB correct
11 Correct 2 ms 376 KB correct
12 Correct 3 ms 256 KB correct
13 Correct 15 ms 364 KB correct
14 Incorrect 3 ms 376 KB WA in grader: NO
15 Halted 0 ms 0 KB -