結果

問題 No.812 Change of Class
ユーザー tkmst201
提出日時 2021-02-25 15:02:53
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 133 ms / 4,000 ms
コード長 1,405 bytes
コンパイル時間 1,863 ms
コンパイル使用メモリ 203,084 KB
最終ジャッジ日時 2025-01-19 04:27:24
ジャッジサーバーID
(参考情報)
judge3 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 60
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:22:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   22 |                 scanf("%d %d", &p, &q);
      |                 ~~~~~^~~~~~~~~~~~~~~~~
main.cpp:47:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   47 |                 scanf("%d", &A);
      |                 ~~~~~^~~~~~~~~~

ソースコード

diff #
プレゼンテーションモードにする

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = false;
//---------------------------------//
int main() {
int N, M;
cin >> N >> M;
vector<vector<int>> g(N);
REP(i, M) {
int p, q;
scanf("%d %d", &p, &q);
--p; --q;
g[p].emplace_back(q);
g[q].emplace_back(p);
}
auto func = [&](int st) -> pii {
vector<int> dist(N, INF);
queue<int> que;
dist[st] = 0;
que.emplace(st);
int cnt = 0, mxd = 0;
while (!que.empty()) {
int u = que.front(); que.pop();
++cnt;
chmax(mxd, dist[u]);
for (int v : g[u]) if (chmin(dist[v], dist[u] + 1)) que.emplace(v);
}
return {cnt, mxd};
};
int Q;
cin >> Q;
while (Q--) {
int A;
scanf("%d", &A);
--A;
auto [cnt, mxd] = func(A);
--cnt;
if (mxd <= 1) printf("%d %d\n", cnt, 0);
else {
for (int i = 16; i >= 0; --i) if ((mxd - 1) >> i & 1) {
printf("%d %d\n", cnt, i + 1);
break;
}
}
}
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0