답안 #292670

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
292670 2020-09-07T11:35:21 Z Haunted_Cpp Simurgh (IOI17_simurgh) C++17
30 / 100
3000 ms 3576 KB
#include "simurgh.h"
#include <bits/stdc++.h>
using namespace std;

struct DisjointSet {
  vector<int> par, size;
  DisjointSet(int n) {
    par = size = vector<int>(n);
    for (int i = 0; i < n; i++) {
      par[i] = i;
      size[i] = 1;
    }
  }
  int root(int x) {
    if (x == par[x]) return x;
    return par[x] = root(par[x]);
  }
  void join(int a, int b) {
    a = root(a);
    b = root(b);
    if (a == b) return;
    if (size[a] < size[b]) swap(a, b);
    par[b] = a;
    size[a] += size[b];
  }
  bool is(int a, int b) {
    return root(a) == root(b);
  }
  bool works(const vector<int> &span, const vector<int> &u, const vector<int> &v) {
    for (auto to : span) {
      const int st = u[to];
      const int et = v[to];
      if (is(st, et)) return false;
      join(st, et);
    }
    return true;
  }
};

const int MAX_N = 240 + 5;

vector<vector<pair<int, int>>> g(MAX_N);
bitset<MAX_N> vis;

vector<int> span;

void get_any(int node) {
  vis[node] = 1;
  for (auto [nxt, to] : g[node]) {
    if (!vis[nxt]) {
      vis[nxt] = 1;
      span.emplace_back(to);
      get_any(nxt);
    }
  }  
}

vector<int> find_roads(int n, vector<int> u, vector<int> v) {
  const int m = v.size();
  const int t = n - 1;
  for (int i = 0; i < m; i++) {
    const int st = u[i];
    const int et = v[i];
    g[st].emplace_back(et, i);
    g[et].emplace_back(st, i);
  }
  get_any(0);
  int score = count_common_roads(span);
  if (score == t) {
    return span;
  }
  for (auto &edge : span) {
    int starting_edge = edge;
    bool swap = false;
    for (int i = 0; i < m; i++) {
      DisjointSet DSU(n);
      edge = i;
      if(!DSU.works(span, u, v)) {
        continue;
      }
      int nxt_score = count_common_roads(span);
      if (nxt_score > score) {
        score = nxt_score;
        assert(edge == i);
        swap = true;
        break;
      }
    }
    if (!swap) {
      edge = starting_edge;
    }
  }
  return span;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB correct
2 Correct 1 ms 384 KB correct
3 Correct 1 ms 384 KB correct
4 Correct 1 ms 384 KB correct
5 Correct 0 ms 384 KB correct
6 Correct 0 ms 384 KB correct
7 Correct 1 ms 384 KB correct
8 Correct 0 ms 384 KB correct
9 Correct 1 ms 384 KB correct
10 Correct 1 ms 384 KB correct
11 Correct 1 ms 384 KB correct
12 Correct 1 ms 384 KB correct
13 Correct 1 ms 384 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB correct
2 Correct 1 ms 384 KB correct
3 Correct 1 ms 384 KB correct
4 Correct 1 ms 384 KB correct
5 Correct 0 ms 384 KB correct
6 Correct 0 ms 384 KB correct
7 Correct 1 ms 384 KB correct
8 Correct 0 ms 384 KB correct
9 Correct 1 ms 384 KB correct
10 Correct 1 ms 384 KB correct
11 Correct 1 ms 384 KB correct
12 Correct 1 ms 384 KB correct
13 Correct 1 ms 384 KB correct
14 Correct 40 ms 384 KB correct
15 Correct 31 ms 384 KB correct
16 Correct 37 ms 384 KB correct
17 Correct 38 ms 384 KB correct
18 Correct 15 ms 384 KB correct
19 Correct 41 ms 384 KB correct
20 Correct 30 ms 384 KB correct
21 Correct 35 ms 384 KB correct
22 Correct 27 ms 384 KB correct
23 Correct 24 ms 412 KB correct
24 Correct 26 ms 384 KB correct
25 Correct 5 ms 384 KB correct
26 Correct 26 ms 384 KB correct
27 Correct 27 ms 384 KB correct
28 Correct 11 ms 384 KB correct
29 Correct 7 ms 384 KB correct
30 Correct 31 ms 400 KB correct
31 Correct 31 ms 384 KB correct
32 Correct 32 ms 384 KB correct
33 Correct 30 ms 384 KB correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB correct
2 Correct 1 ms 384 KB correct
3 Correct 1 ms 384 KB correct
4 Correct 1 ms 384 KB correct
5 Correct 0 ms 384 KB correct
6 Correct 0 ms 384 KB correct
7 Correct 1 ms 384 KB correct
8 Correct 0 ms 384 KB correct
9 Correct 1 ms 384 KB correct
10 Correct 1 ms 384 KB correct
11 Correct 1 ms 384 KB correct
12 Correct 1 ms 384 KB correct
13 Correct 1 ms 384 KB correct
14 Correct 40 ms 384 KB correct
15 Correct 31 ms 384 KB correct
16 Correct 37 ms 384 KB correct
17 Correct 38 ms 384 KB correct
18 Correct 15 ms 384 KB correct
19 Correct 41 ms 384 KB correct
20 Correct 30 ms 384 KB correct
21 Correct 35 ms 384 KB correct
22 Correct 27 ms 384 KB correct
23 Correct 24 ms 412 KB correct
24 Correct 26 ms 384 KB correct
25 Correct 5 ms 384 KB correct
26 Correct 26 ms 384 KB correct
27 Correct 27 ms 384 KB correct
28 Correct 11 ms 384 KB correct
29 Correct 7 ms 384 KB correct
30 Correct 31 ms 400 KB correct
31 Correct 31 ms 384 KB correct
32 Correct 32 ms 384 KB correct
33 Correct 30 ms 384 KB correct
34 Execution timed out 3052 ms 1536 KB Time limit exceeded
35 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB correct
2 Correct 1 ms 384 KB correct
3 Runtime error 22 ms 3576 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB correct
2 Correct 1 ms 384 KB correct
3 Correct 1 ms 384 KB correct
4 Correct 1 ms 384 KB correct
5 Correct 0 ms 384 KB correct
6 Correct 0 ms 384 KB correct
7 Correct 1 ms 384 KB correct
8 Correct 0 ms 384 KB correct
9 Correct 1 ms 384 KB correct
10 Correct 1 ms 384 KB correct
11 Correct 1 ms 384 KB correct
12 Correct 1 ms 384 KB correct
13 Correct 1 ms 384 KB correct
14 Correct 40 ms 384 KB correct
15 Correct 31 ms 384 KB correct
16 Correct 37 ms 384 KB correct
17 Correct 38 ms 384 KB correct
18 Correct 15 ms 384 KB correct
19 Correct 41 ms 384 KB correct
20 Correct 30 ms 384 KB correct
21 Correct 35 ms 384 KB correct
22 Correct 27 ms 384 KB correct
23 Correct 24 ms 412 KB correct
24 Correct 26 ms 384 KB correct
25 Correct 5 ms 384 KB correct
26 Correct 26 ms 384 KB correct
27 Correct 27 ms 384 KB correct
28 Correct 11 ms 384 KB correct
29 Correct 7 ms 384 KB correct
30 Correct 31 ms 400 KB correct
31 Correct 31 ms 384 KB correct
32 Correct 32 ms 384 KB correct
33 Correct 30 ms 384 KB correct
34 Execution timed out 3052 ms 1536 KB Time limit exceeded
35 Halted 0 ms 0 KB -