답안 #908714

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
908714 2024-01-16T17:32:38 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;

std::vector<int> find_roads(int n, std::vector<int> u, std::vector<int> v);
int count_common_roads(const std::vector<int>& r);

bool isSubtask1(int n) {return n<=7;}
bool isSubtask2(int n) {return n<=50;}
bool isSubtask3(int n) {return n<=240;}

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);
    }
    // cout << "edge numbers: "; for(int elem: r) cout << elem << " "; cout << endl;
    vector<int> visit(n,0);
    dfs(-1,u[r[0]],visit,edgeL);
	for(int i=0; i<n; i++)
		if(!visit[i]) return false;
	// cout << "tree\n"; 
	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;
    if (cnt == n-1){
		// if (r[0]==2) for(int elem: r) printf("%d ", elem); cout << endl;
        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:19:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   19 |     for(int elem: edgeL[now])
      |     ^~~
simurgh.cpp:22:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   22 |  return;
      |  ^~~~~~
simurgh.cpp: In function 'bool selectEdges(int, int, std::vector<int>&, std::vector<int>&, std::vector<int>&)':
simurgh.cpp:49:24: error: 'm' was not declared in this scope
   49 |     for(int i=start; i<m; i++){
      |                        ^