제출 #647475

#제출 시각아이디문제언어결과실행 시간메모리
647475a_aguiloSimurgh (IOI17_simurgh)C++14
13 / 100
3074 ms308 KiB
#include "simurgh.h"
#include<bits/stdc++.h>

using namespace std;

vector<int> padre;
int N;
vector<int> choices;

int raiz(int nodo){
    if(padre[nodo] == nodo) return nodo;
    return raiz(padre[nodo]);
}

bool getTree(int pos, vector<pair<int, int>>& edges){
    //cout << pos << endl;
    if(pos == edges.size()){
        if(choices.size() == N-1){
            //cout << "submit" << endl;
            //print(choices);
            if(count_common_roads(choices) == N-1) {
                    //cout << "yes "<< endl;
                    return true;
            }
            return false;
        }
        else return false;
    }
    pair<int, int> actEdge = edges[pos];
    int a = actEdge.first; int b = actEdge.second;
    int rootA = raiz(a); int rootB = raiz(b);
    if (getTree(pos+1, edges)) return true;
    else if (rootA!=rootB) {
        padre[rootB] = rootA;
        choices.push_back(pos);
        bool ret = getTree(pos+1, edges);
        padre[rootB] = rootB;
        if(ret) return true;
        choices.pop_back();
    }
    return false;
}

vector<int> find_roads(int n, vector<int> u, vector<int> v) {
	N = n;
	vector<pair<int, int>> edges(u.size());
	choices = vector<int>();
	for(int i = 0; i < u.size(); ++i){
        edges[i] = {u[i], v[i]};
	}
	padre = vector<int>(n);
	for(int i = 0; i < n; ++i) padre[i] = i;
	getTree(0, edges);
	return choices;
}

컴파일 시 표준 에러 (stderr) 메시지

simurgh.cpp: In function 'bool getTree(int, std::vector<std::pair<int, int> >&)':
simurgh.cpp:17:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |     if(pos == edges.size()){
      |        ~~~~^~~~~~~~~~~~~~~
simurgh.cpp:18:27: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   18 |         if(choices.size() == N-1){
      |            ~~~~~~~~~~~~~~~^~~~~~
simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:48:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |  for(int i = 0; i < u.size(); ++i){
      |                 ~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...