Submission #938926

# Submission time Handle Problem Language Result Execution time Memory
938926 2024-03-05T21:18:18 Z Macker Simurgh (IOI17_simurgh) C++17
0 / 100
1 ms 348 KB
#include "simurgh.h"
#include <bits/stdc++.h>

typedef long long ll;
#define pii pair<int, int>
#define fi first
#define se second
#define all(v) v.begin(), v.end()
#define FOR(i, n) for (int i = 0; i < n; i++)

using namespace std;

set<pii> cur;
map<pii, int> fin;
map<pii, int> label;
vector<vector<int>> adj;
vector<int> vis;

vector<int> tovec(set<pii> a){
	vector<int> res;
	for (auto &i : a) {
		res.push_back(label[i]);
	}
	return res;
}

pii sdfs(int a, int p){
	vis[a] = 2;
	pii res = {1, 0};
	for (auto &b : adj[a]) {
		if(vis[b] != 2) {
			pii ret = sdfs(b, a);
			res.fi += ret.fi;
			res.se += ret.se;
		}
	}
	if(a == 0) return res;

	int base = count_common_roads(tovec(cur));
	cur.erase({p, a});
	set<int> samepar;
	bool parroyal = (res.se < res.fi);
	for (auto &b : adj[a]) {
		if(cur.find({a, b}) == cur.end() && cur.find({b, a}) == cur.end()){
			cur.insert({a, b});
			int cnt = count_common_roads(tovec(cur));
			cur.erase({a, b});
			if(cnt == base) samepar.insert(b);
			if(cnt < base) parroyal = 1;
			if(cnt > base) parroyal = 0;
		}
	}
	for (auto &b : adj[a]) {
		if(cur.find({a, b}) == cur.end() && cur.find({b, a}) == cur.end()){
			if(samepar.find(b) != samepar.end()){
				if(parroyal) {
					cur.insert({a, b});
					fin[{a, b}] = 1;
					res.se++;
				}
			}
			else {
				if(!parroyal) {
					cur.insert({a, b});
					fin[{a, b}] = 1;
					res.se++;
				}
			}
		}
	}
	return res;
}

void dfs(int a){
	vis[a] = 1;
	for (auto &b : adj[a]) {
		if(!vis[b]) {
			cur.insert({a, b});
			dfs(b);
		}
	}
}

vector<int> find_roads(int n, vector<int> u, vector<int> v) {
	adj.resize(n);
	vis.resize(n);
	FOR(i, u.size()){
		adj[u[i]].push_back(v[i]);
		adj[v[i]].push_back(u[i]);
		label[{u[i], v[i]}] = i;
		label[{v[i], u[i]}] = i;
	}
	dfs(0);
	sdfs(0, 0);

	vector<int> res;
	for (auto &i : fin) {
		if(i.se == 1) res.push_back(label[i.fi]);
	}
	return res;
}

Compilation message

simurgh.cpp: In function 'std::vector<int> find_roads(int, std::vector<int>, std::vector<int>)':
simurgh.cpp:9:37: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    9 | #define FOR(i, n) for (int i = 0; i < n; i++)
......
   87 |  FOR(i, u.size()){
      |      ~~~~~~~~~~~                     
simurgh.cpp:87:2: note: in expansion of macro 'FOR'
   87 |  FOR(i, u.size()){
      |  ^~~
# 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 348 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 Correct 1 ms 348 KB correct
2 Incorrect 0 ms 348 KB WA in grader: NO
3 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 -