답안 #280234

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
280234 2020-08-22T15:08:37 Z Haunted_Cpp Hotspot (NOI17_hotspot) C++17
38 / 100
25 ms 1436 KB
/**
 *  author: Haunted_Cpp
**/
 
#include <bits/stdc++.h>
using namespace std;
 
#pragma GCC optimize("Ofast")
#pragma GCC target("fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("unroll-loops")
 
template<typename T> ostream &operator << (ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename T, size_t size> ostream &operator << (ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream &operator << (ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
 
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail> void debug_out(Head H, Tail... T) { cerr << ' ' << H; debug_out(T...); }
 
#ifdef LOCAL
#define debug(...) cerr << "(" << #__VA_ARGS__ << "):", debug_out(__VA_ARGS__)
#else
#define debug(...) 47
#endif

const int MAX_N = 5000 + 5;
const int MAX_K = 2000 + 5;

vector<vector<int>> g(MAX_N);
vector<double> ans(MAX_N); 

int solve(int node, int target, const vector<vector<int>> &dag, vector<int> &dp) {
  if (node == target) return 1;
  int &res = dp[node];
  if (~res) return res;
  res = 0;
  for (auto to : dag[node]) {
    res += solve(to, target, dag, dp);
  }
  return res;
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0); 
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int st, et;
    cin >> st >> et;
    g[st].emplace_back(et);
    g[et].emplace_back(st);
  }
  auto bfs = [&](int source, int sink) {
    queue<int> q;
    vector<int> dist(n, 1e9);
    dist[sink] = 0;
    q.push(sink);
    while(!q.empty()) {
      int node = q.front();
      q.pop();
      for (auto to : g[node]) {
        if (dist[to] > dist[node] + 1) {
          dist[to] = dist[node] + 1;
          q.push(to);
        }
      }
    }
    vector<vector<int>> dag(MAX_N);
    function<void(int)> build_dag = [&](int node) {
      const int cur = dist[node];
      for (auto to : g[node]) {
        if (dist[to] == cur - 1) {
          dag[node].emplace_back(to);
          build_dag(to);
        }
      }
    };
    build_dag(source);
    return dag;
  };
  int k;
  cin >> k;
  while(k--) {
    int source, sink;
    cin >> source >> sink;
    vector<vector<int>> a = bfs(source, sink);
    vector<int> dp_a(MAX_N, -1);
    vector<vector<int>> b = bfs(sink, source);
    vector<int> dp_b(MAX_N, -1);
    const int cnt_shortest = solve(source, sink, a, dp_a);
    for (int i = 0; i < n; i++) {
      int L = solve(i, sink, a, dp_a);
      int R = solve(i, source, b, dp_b);
      ans[i] += 1.0 * L * R / cnt_shortest;
    }
  }
  cout << (max_element(ans.begin(), ans.end()) - ans.begin()) << '\n';
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 768 KB Output is correct
2 Correct 1 ms 896 KB Output is correct
3 Correct 1 ms 768 KB Output is correct
4 Correct 1 ms 768 KB Output is correct
5 Correct 1 ms 768 KB Output is correct
6 Correct 1 ms 768 KB Output is correct
7 Correct 1 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 768 KB Output is correct
2 Correct 1 ms 896 KB Output is correct
3 Correct 1 ms 768 KB Output is correct
4 Correct 1 ms 768 KB Output is correct
5 Correct 1 ms 768 KB Output is correct
6 Correct 1 ms 768 KB Output is correct
7 Correct 1 ms 768 KB Output is correct
8 Correct 1 ms 768 KB Output is correct
9 Correct 1 ms 768 KB Output is correct
10 Correct 1 ms 768 KB Output is correct
11 Correct 1 ms 768 KB Output is correct
12 Correct 1 ms 768 KB Output is correct
13 Correct 1 ms 768 KB Output is correct
14 Correct 1 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 768 KB Output is correct
2 Correct 1 ms 896 KB Output is correct
3 Correct 1 ms 768 KB Output is correct
4 Correct 1 ms 768 KB Output is correct
5 Correct 1 ms 768 KB Output is correct
6 Correct 1 ms 768 KB Output is correct
7 Correct 1 ms 768 KB Output is correct
8 Correct 7 ms 864 KB Output is correct
9 Correct 12 ms 944 KB Output is correct
10 Correct 12 ms 928 KB Output is correct
11 Correct 18 ms 980 KB Output is correct
12 Correct 12 ms 828 KB Output is correct
13 Correct 14 ms 832 KB Output is correct
14 Correct 25 ms 1436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 768 KB Output is correct
2 Correct 1 ms 896 KB Output is correct
3 Correct 1 ms 768 KB Output is correct
4 Correct 1 ms 768 KB Output is correct
5 Correct 1 ms 768 KB Output is correct
6 Correct 1 ms 768 KB Output is correct
7 Correct 1 ms 768 KB Output is correct
8 Correct 1 ms 768 KB Output is correct
9 Correct 1 ms 768 KB Output is correct
10 Correct 1 ms 768 KB Output is correct
11 Correct 1 ms 768 KB Output is correct
12 Correct 1 ms 768 KB Output is correct
13 Correct 1 ms 768 KB Output is correct
14 Correct 1 ms 768 KB Output is correct
15 Correct 7 ms 864 KB Output is correct
16 Correct 12 ms 944 KB Output is correct
17 Correct 12 ms 928 KB Output is correct
18 Correct 18 ms 980 KB Output is correct
19 Correct 12 ms 828 KB Output is correct
20 Correct 14 ms 832 KB Output is correct
21 Correct 25 ms 1436 KB Output is correct
22 Correct 7 ms 912 KB Output is correct
23 Correct 8 ms 840 KB Output is correct
24 Correct 12 ms 976 KB Output is correct
25 Correct 15 ms 956 KB Output is correct
26 Correct 17 ms 860 KB Output is correct
27 Correct 16 ms 828 KB Output is correct
28 Correct 22 ms 840 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 768 KB Output is correct
2 Correct 1 ms 896 KB Output is correct
3 Correct 1 ms 768 KB Output is correct
4 Correct 1 ms 768 KB Output is correct
5 Correct 1 ms 768 KB Output is correct
6 Correct 1 ms 768 KB Output is correct
7 Correct 1 ms 768 KB Output is correct
8 Correct 1 ms 768 KB Output is correct
9 Correct 1 ms 768 KB Output is correct
10 Correct 1 ms 768 KB Output is correct
11 Correct 1 ms 768 KB Output is correct
12 Correct 1 ms 768 KB Output is correct
13 Correct 1 ms 768 KB Output is correct
14 Correct 1 ms 768 KB Output is correct
15 Correct 3 ms 896 KB Output is correct
16 Correct 2 ms 896 KB Output is correct
17 Correct 10 ms 968 KB Output is correct
18 Incorrect 5 ms 892 KB Output isn't correct
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 768 KB Output is correct
2 Correct 1 ms 896 KB Output is correct
3 Correct 1 ms 768 KB Output is correct
4 Correct 1 ms 768 KB Output is correct
5 Correct 1 ms 768 KB Output is correct
6 Correct 1 ms 768 KB Output is correct
7 Correct 1 ms 768 KB Output is correct
8 Correct 1 ms 768 KB Output is correct
9 Correct 1 ms 768 KB Output is correct
10 Correct 1 ms 768 KB Output is correct
11 Correct 1 ms 768 KB Output is correct
12 Correct 1 ms 768 KB Output is correct
13 Correct 1 ms 768 KB Output is correct
14 Correct 1 ms 768 KB Output is correct
15 Correct 7 ms 864 KB Output is correct
16 Correct 12 ms 944 KB Output is correct
17 Correct 12 ms 928 KB Output is correct
18 Correct 18 ms 980 KB Output is correct
19 Correct 12 ms 828 KB Output is correct
20 Correct 14 ms 832 KB Output is correct
21 Correct 25 ms 1436 KB Output is correct
22 Correct 7 ms 912 KB Output is correct
23 Correct 8 ms 840 KB Output is correct
24 Correct 12 ms 976 KB Output is correct
25 Correct 15 ms 956 KB Output is correct
26 Correct 17 ms 860 KB Output is correct
27 Correct 16 ms 828 KB Output is correct
28 Correct 22 ms 840 KB Output is correct
29 Correct 3 ms 896 KB Output is correct
30 Correct 2 ms 896 KB Output is correct
31 Correct 10 ms 968 KB Output is correct
32 Incorrect 5 ms 892 KB Output isn't correct
33 Halted 0 ms 0 KB -