結果
| 問題 |
No.812 Change of Class
|
| コンテスト | |
| ユーザー |
Shibuyap
|
| 提出日時 | 2020-09-08 03:51:31 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,504 bytes |
| コンパイル時間 | 2,140 ms |
| コンパイル使用メモリ | 199,796 KB |
| 最終ジャッジ日時 | 2025-01-14 08:28:59 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 WA * 2 |
| other | AC * 5 WA * 55 |
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
struct edge{ int to, cost, id; };
const int INF = 1001001001;
const int MAX_N = 200005;
vector<edge> G[MAX_N];
int main() {
int n, m;
cin >> n >> m;
rep(i,m){
int from = 0, to = 0, cost = 1, id = i;;
cin >> from >> to;
from--; to--;
edge e1, e2;
e1.to = to; e1.cost = cost; e1.cost = cost; e1.id = id;
e2.to = from; e2.cost = cost; e2.cost = cost; e2.id = id;
G[from].push_back(e1);
G[to].push_back(e2);
}
int Q;
cin >> Q;
rep(_,Q){
int a; cin >> a;
a--;
queue<int> que;
que.push(a);
int d[n] = {};
int f[n] = {};
f[a] = 1;
while(que.size()>0){
int x = que.front();
que.pop();
rep(i,G[x].size()){
int y = G[x][i].to;
if(f[y]) continue;
d[y] = d[x]+1;
f[y] = 1;
que.push(y);
}
}
int ans = -1;
int ma = 0;
rep(i,n){
if(f[i]){
ans++;
ma = max(ma,d[i]);
}
}
ma--;
cout << ans << ' ' << ma << endl;
}
return 0;
}
Shibuyap