답안 #201325

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
201325 2020-02-10T08:13:40 Z dimash241 Meetings (JOI19_meetings) C++17
29 / 100
2000 ms 16376 KB
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")
 
//# include <x86intrin.h>
#include "meetings.h"
 
# include <bits/stdc++.h>
 
# include <ext/pb_ds/assoc_container.hpp>
# include <ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;
 
template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define For(i,x,y)  for (ll i = x; i <= y; i ++) 
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
// ROAD to...                                                                                                                                                                                                                Red
 
inline void Input_Output () {
	//freopen(".in", "r", stdin);
   //freopen(".out", "w", stdout);
}
 
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
 
int n, m, k;
vector < int > g[2020];
int e[2020][2020];
int deg[2020];
int u[2020];
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
void Bridge (int, int);
int Query (int, int, int);
int opera = 0;
 
void PrintOut(int a, int b) {
	if (a > b) swap(a, b);
	opera++;
	if (opera == n) {
		assert(0);
	}
	Bridge(a, b);
}
 
void reduce (vector < int > &v) {
//	sort(every(v));
//	v.resize(unique(every(v)) - v.begin());
	random_shuffle(every(v));
}
 
 
void Solve(int N) {
	opera = 0;
	n = N;
	set < int > p;
	for (int i = 0; i < n; i ++) {
		g[i].clear();
		deg[i] = 0;
		u[i] = 0;
		p.insert(i);
		for (int j = 0; j < n; ++j)
			e[i][j] = 0;
	}  	
 
	for (int i = 1; i < n; ++i) {
	    if (!e[0][i]) {
		//	g[0].pb(i);
			e[0][i] = 1;
			deg[i]++;
		}
		for (int j = i + 1; j < n; ++j) {
			int x = Query(0, i, j);
			if (x != j) {
				if (!e[x][j]) {
		//			g[x].pb(j);
					e[x][j] = 1;
					deg[j]++;
				}
			}
			if (x != i) {
				if (!e[x][i]) {
	//				g[x].pb(i);
					e[x][i] = 1;
					deg[i]++;
				}
			}
		}
	}
 
	
	queue < int > q;
	q.push(0);
	p.erase(0);
	while(q.size()) {
		int v = q.front();
		q.pop();
		u[v] = 1;
 
		for (int to : p) if (e[v][to]) deg[to]--;
		vector < int > del;
		for (int to : p) if (e[v][to] && deg[to] == 0 && !u[to]) {
			PrintOut(v, to);
			u[to] = 1;     
			del.pb(to);
			q.push(to);
		}
		for (auto it : del) p.erase(it);
	}
	if (opera != n-1) assert(0);
}
 
 
/*namespace {
 
const int MAX_N = 2000;
const int MAX_CALLS = 100000;
 
void WrongAnswer(int code) {
  printf("Wrong Answer [%d]\n", code);
  exit(0);
}
 
int N, num_calls;
std::vector<int> graph[MAX_N];
std::set<std::pair<int, int>> edges, edges_reported;
 
int weight[MAX_N];
 
bool Visit(int p, int e, int rt = -1) {
  if (p == e) {
    ++weight[p];
    return true;
  }
  for (int q : graph[p]) {
    if (q != rt) {
      if (Visit(q, e, p)) {
        ++weight[p];
        return true;
      }
    }
  }
  return false;
}
 
}  // namespace
 
int Query(int u, int v, int w) {
  if (!(0 <= u && u <= N - 1 && 0 <= v && v <= N - 1 && 0 <= w && w <= N - 1 &&
        u != v && u != w && v != w)) {
    WrongAnswer(1);
  }
  if (++num_calls > MAX_CALLS) {
    WrongAnswer(2);
  }
  std::fill(weight, weight + N, 0);
  Visit(u, v);
  Visit(u, w);
  Visit(v, w);
  for (int x = 0; x < N; ++x) {
    if (weight[x] == 3) {
      return x;
    }
  }
  printf("Error: the input may be invalid\n");
  exit(0);
}
 
void Bridge(int u, int v) {
  if (!(0 <= u && u < v && v <= N - 1)) {
    WrongAnswer(3);
  }
  if (!(edges.count(std::make_pair(u, v)) >= 1)) {
    WrongAnswer(4);
  }
  if (!(edges_reported.count(std::make_pair(u, v)) == 0)) {
    WrongAnswer(5);
  }
  edges_reported.insert(std::make_pair(u, v));
}
 
int main() {
  if (scanf("%d", &N) != 1) {
    fprintf(stderr, "Error while reading input\n");
    exit(1);
  }
  for (int i = 0; i < N - 1; ++i) {
    int u, v;
    if (scanf("%d%d", &u, &v) != 2) {
      fprintf(stderr, "Error while reading input\n");
      exit(1);
    }
    graph[u].push_back(v);
    graph[v].push_back(u);
    edges.insert(std::make_pair(u, v));
  }
 
  num_calls = 0;
  Solve(N);
  if (edges_reported.size() != static_cast<size_t>(N - 1)) {
    WrongAnswer(6);
  }
  printf("Accepted: %d\n", num_calls);
  return 0;
}
 
// B...a   */
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 380 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 504 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 6 ms 504 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 380 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 504 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 6 ms 504 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 6 ms 632 KB Output is correct
15 Correct 6 ms 632 KB Output is correct
16 Correct 5 ms 632 KB Output is correct
17 Correct 6 ms 632 KB Output is correct
18 Correct 6 ms 632 KB Output is correct
19 Correct 5 ms 632 KB Output is correct
20 Correct 6 ms 632 KB Output is correct
21 Correct 6 ms 632 KB Output is correct
22 Correct 5 ms 632 KB Output is correct
23 Correct 6 ms 632 KB Output is correct
24 Correct 6 ms 632 KB Output is correct
25 Correct 6 ms 632 KB Output is correct
26 Correct 6 ms 632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 380 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 504 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 6 ms 504 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 6 ms 632 KB Output is correct
15 Correct 6 ms 632 KB Output is correct
16 Correct 5 ms 632 KB Output is correct
17 Correct 6 ms 632 KB Output is correct
18 Correct 6 ms 632 KB Output is correct
19 Correct 5 ms 632 KB Output is correct
20 Correct 6 ms 632 KB Output is correct
21 Correct 6 ms 632 KB Output is correct
22 Correct 5 ms 632 KB Output is correct
23 Correct 6 ms 632 KB Output is correct
24 Correct 6 ms 632 KB Output is correct
25 Correct 6 ms 632 KB Output is correct
26 Correct 6 ms 632 KB Output is correct
27 Correct 172 ms 2108 KB Output is correct
28 Correct 166 ms 1912 KB Output is correct
29 Correct 167 ms 2040 KB Output is correct
30 Correct 172 ms 2040 KB Output is correct
31 Correct 175 ms 2044 KB Output is correct
32 Correct 177 ms 2040 KB Output is correct
33 Correct 160 ms 1912 KB Output is correct
34 Correct 152 ms 2092 KB Output is correct
35 Correct 152 ms 2028 KB Output is correct
36 Correct 172 ms 2040 KB Output is correct
37 Correct 249 ms 2168 KB Output is correct
38 Correct 238 ms 2040 KB Output is correct
39 Correct 216 ms 2168 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3083 ms 16376 KB Time limit exceeded
2 Halted 0 ms 0 KB -