結果

問題 No.812 Change of Class
ユーザー hide1214hide1214
提出日時 2019-04-12 22:30:01
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,316 bytes
コンパイル時間 1,023 ms
コンパイル使用メモリ 109,984 KB
実行使用メモリ 18,716 KB
最終ジャッジ日時 2023-09-03 13:38:50
合計ジャッジ時間 17,343 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 7 ms
11,524 KB
testcase_08 AC 6 ms
11,716 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 18 ms
12,448 KB
testcase_12 WA -
testcase_13 AC 5 ms
11,592 KB
testcase_14 AC 5 ms
11,540 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 AC 9 ms
11,828 KB
testcase_39 WA -
testcase_40 WA -
testcase_41 AC 9 ms
11,792 KB
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 AC 286 ms
15,848 KB
testcase_56 AC 339 ms
17,924 KB
testcase_57 AC 362 ms
18,060 KB
testcase_58 AC 182 ms
14,780 KB
testcase_59 AC 413 ms
18,716 KB
testcase_60 AC 5 ms
11,556 KB
testcase_61 AC 5 ms
11,592 KB
testcase_62 AC 5 ms
11,656 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<algorithm>
#include<functional>
#include<numeric>
#include<queue>
#include<stack>
#include<map>
#include<unordered_map>
#include<set>
#include<bitset>
#include<random>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0LL,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0LL,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define COUNT(a,y,x) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define pb push_back
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
const ll inf = 2222222222222222222LL;
const ll mod = 1000000007LL;

ll n = 0, m = 0, ans = 0, tmp = 0, ma = -inf, mi = inf;
string s;
bool ok;
ll dx[9] = { 0,1,-1,0,0,1,1,-1,-1 }, dy[9] = { 0,0,0,1,-1,1,-1,1,-1 };
#define endl '\n'
#pragma endregion
#define MAX 222222

#define NOT 0
#define VIS 1
#define COMP 2
ll stt[MAX], d[MAX];
vector<pll> edge[MAX];
priority_queue<pll, vector<pll>, greater<pll>> pq;

void dijkstra(ll start) {
  pll mi;
  ll k;
  FOR(i, 1, n + 1) {
    stt[i] = NOT;
    d[i] = inf;
  }
  d[start] = 0;
  pq.push(pll(0, start));

  while (!pq.empty()) {
    mi = pq.top(); pq.pop();
    m = mi.second;
    stt[m] = COMP;
    if (d[m] < mi.first) continue;

    FOR(i, 0, edge[m].size()) {
      k = edge[m][i].first;
      if (stt[k] != COMP) {
        if (edge[m][i].second + d[m] < d[k]) {
          d[k] = edge[m][i].second + d[m];
          stt[k] = VIS;
          pq.push(pll(d[k], k));
        }
      }
    }
  }

}


int main(void) {
  ios::sync_with_stdio(false); cin.tie(0);


  ll q;
  cin >> n >> q;
  rep(i, q) {
    ll a, b;
    cin >> a >> b;
    edge[a].pb(pll(b, 1));
    edge[b].pb(pll(a, 1));
  }
  cin >> q;
  rep(i, q) {
    ll a;
    cin >> a;
    dijkstra(a);
    ans = 0;
    ma = 0;
    FOR(j, 1, n + 1) {
      if (j == a) continue;
      if (d[j] > inf / 2) continue;
      ma = max(ma, d[j]);
      ans++;
    }
    if (ma == 1) ma = 0;
    cout << ans << " " << (ma + 1) / 2 << endl;
  }


  

  return 0;
}
0