結果
| 問題 |
No.2638 Initial fare
|
| コンテスト | |
| ユーザー |
👑 |
| 提出日時 | 2024-02-11 14:06:54 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,258 bytes |
| コンパイル時間 | 2,211 ms |
| コンパイル使用メモリ | 202,848 KB |
| 最終ジャッジ日時 | 2025-02-19 05:05:04 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 1 TLE * 1 -- * 23 |
ソースコード
//all checkup with acceleration
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
ll N;
cin >> N;
vector<vector<ll>> g(N);
rep(i,N-1){
ll s,t;
cin >> s >> t;
s--;
t--;
g[s].push_back(t);
g[t].push_back(s);
}
queue<pair<ll,ll>> q;
rep(i,N){
q.push(make_pair(i,0));
}
ll ans=0;
rep(i,N){
vector<ll> seen(N);
queue<pair<ll,ll>> q;
q.push(make_pair(i,0));
seen[i]=1;
while(!q.empty()){
ll c=q.front().first;
ll v=q.front().second;
q.pop();
//cout << i << " " << c << endl;
if(v!=0)ans++;
if(v!=2){
for (const auto& e : g[c]) {
if (seen[e]==0){
q.push(make_pair(e,v+1));
seen[e]=1;
}
}
}else{
for (const auto& e : g[c]) {
if (seen[e]==0){
ans++;
seen[e]=1;
}
}
}
}
}
cout << ans/2 << endl;
}