답안 #681940

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
681940 2023-01-14T22:58:24 Z Mher777 Easter Eggs (info1cup17_eastereggs) C++17
0 / 100
1 ms 464 KB
#include <iostream>
#include <iomanip>
#include <array>
#include <string>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <list>
#include <iterator>
#include <numeric>
#include <complex>
#include <utility>
#include <random>
#include <fstream>
#include "grader.h"
using namespace std;

const int N = 600;

vector<int> g[N];
vector<bool> used(N);

void dfs(int u, vector<int> v) {
	used[u] = 1;
	for (int i = 0; i < g[u].size(); i++) {
		if (!used[g[u][i]]) {
			used[g[u][i]] = true;
			v.push_back(g[u][i]);
			dfs(g[u][i], v);
		}
	}
}

int findEgg (int n, vector<pair<int,int>> b) {
	for (int i = 0; i < b.size(); i++) {
		if (b[i].second < b[i].first) swap(b[i].first, b[i].second);
		g[b[i].first].push_back(b[i].second);
	}
	for (int i = 1; i <= n; i++) {
		if (!used[i]) {
			vector<int> v, v1;
			v.push_back(i);
			dfs(i, v);
			if (query(v) == -1) continue;
			int l = 0, r = v.size() - 1, mid = (l + r) / 2;
			while (l < r) {
				mid = (l + r) / 2;
				for (int i = 0; i <= mid; i++) {
					v1.push_back(v[i]);
				}
				if (query(v1) == 1) {
					r = mid;
				}
				else {
					l = mid + 1;
					r = (l + v.size() - 1) / 2;
				}
				v1.clear();
			}
			return l;
		}
	}
}

Compilation message

eastereggs.cpp: In function 'void dfs(int, std::vector<int>)':
eastereggs.cpp:33:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |  for (int i = 0; i < g[u].size(); i++) {
      |                  ~~^~~~~~~~~~~~~
eastereggs.cpp: In function 'int findEgg(int, std::vector<std::pair<int, int> >)':
eastereggs.cpp:43:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |  for (int i = 0; i < b.size(); i++) {
      |                  ~~^~~~~~~~~~
eastereggs.cpp:71:1: warning: control reaches end of non-void function [-Wreturn-type]
   71 | }
      | ^
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 464 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 464 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 464 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -