답안 #908723

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
908723 2024-01-16T17:39:04 Z nightfal Simurgh (IOI17_simurgh) C++14
컴파일 오류
0 ms 0 KB
#include <cstdio>
#include <iostream>
#include <cassert>
#include <vector>
#include <cstdlib>
#include <string>

using namespace std;

void dfs(int parent, int now, std::vector<int>& visit, std::vector<vector<int>>& edgeL) {
    visit[now]=1;
    for(int elem: edgeL[now])
        if (elem!=parent && !visit[elem])
			dfs(now,elem,visit,edgeL);
	return;
}

bool isTree(std::vector<int>& r, std::vector<int>& u, std::vector<int>& v) {
    int n = r.size()+1;
    std::vector<vector<int>> edgeL(n);
    for(int i=0; i<n-1; i++) {
        int s = u[r[i]], e = v[r[i]];
        edgeL[s].push_back(e);
        edgeL[e].push_back(s);
    }
    vector<int> visit(n,0);
    dfs(-1,u[r[0]],visit,edgeL);
	for(int i=0; i<n; i++)
		if(!visit[i]) return false;
	return true;
}

bool selectEdges(int cnt, int start, std::vector<int>& r, std::vector<int>& u, std::vector<int>& v){
	int n = r.size()+1, m = u.size();
    if (cnt == n-1){
        if(isTree(r,u,v) && count_common_roads(r)== n-1) return true;
        else return false;
    }
    for(int i=start; i<m; i++){
        r[cnt] = i;
        if (selectEdges(cnt+1,i+1,r,u,v)) return true;
    }
    return false;
}

std::vector<int> subtask1(int n, std::vector<int>& u, std::vector<int>& v) {
    std::vector<int> r(n-1), zero(n-1,-1);
    if (selectEdges(0,0,r,u,v)) return r;
    else return zero;
}

std::vector<int> find_roads(int n, std::vector<int> u, std::vector<int> v) {
    // if (isSubtask1(n)) 
    return subtask1(n,u,v);
}

Compilation message

simurgh.cpp: In function 'void dfs(int, int, std::vector<int>&, std::vector<std::vector<int> >&)':
simurgh.cpp:12:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   12 |     for(int elem: edgeL[now])
      |     ^~~
simurgh.cpp:15:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   15 |  return;
      |  ^~~~~~
simurgh.cpp: In function 'bool selectEdges(int, int, std::vector<int>&, std::vector<int>&, std::vector<int>&)':
simurgh.cpp:36:29: error: 'count_common_roads' was not declared in this scope
   36 |         if(isTree(r,u,v) && count_common_roads(r)== n-1) return true;
      |                             ^~~~~~~~~~~~~~~~~~