Submission #908712

# Submission time Handle Problem Language Result Execution time Memory
908712 2024-01-16T17:32:00 Z nightfal Simurgh (IOI17_simurgh) C++14
0 / 100
1 ms 348 KB
#include <cstdio>
#include <iostream>
#include <cassert>
#include <vector>
#include <cstdlib>
#include <string>

using namespace std;

static int MAXQ = 30000;

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

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:25:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   25 |     for(int elem: edgeL[now])
      |     ^~~
simurgh.cpp:28:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   28 |  return;
      |  ^~~~~~
simurgh.cpp: At global scope:
simurgh.cpp:12:18: warning: 'q' defined but not used [-Wunused-variable]
   12 | static int n, m, q = 0;
      |                  ^
simurgh.cpp:12:12: warning: 'n' defined but not used [-Wunused-variable]
   12 | static int n, m, q = 0;
      |            ^
simurgh.cpp:10:12: warning: 'MAXQ' defined but not used [-Wunused-variable]
   10 | static int MAXQ = 30000;
      |            ^~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB WA in grader: NO
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB WA in grader: NO
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB WA in grader: NO
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB WA in grader: NO
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB WA in grader: NO
2 Halted 0 ms 0 KB -