結果

問題 No.2638 Initial fare
ユーザー twooimp2twooimp2
提出日時 2024-02-19 23:06:21
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,012 bytes
コンパイル時間 6,752 ms
コンパイル使用メモリ 313,532 KB
実行使用メモリ 146,024 KB
最終ジャッジ日時 2024-02-19 23:06:32
合計ジャッジ時間 10,160 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,480 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 3 ms
6,676 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
using ll=long long;
using P=pair<ll,ll>;

void IO(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
}

void dfs(ll now,set<ll> &seen,ll depth,vector<ll> &used,vector<vector<ll>> &G){
  for(ll next:G[now]){
    if(seen.find(next)==seen.end()){
      if(depth<=2){
        seen.insert(next);
        used.push_back(next);
        dfs(next,seen,depth+1,used,G);
        seen.erase(next);
      }
    }
  }
}

int main(){
  IO();
  ll n;
  cin>>n;
  vector<vector<ll>> G(n);
  for(ll i=0;i<n-1;i++){
    ll u,v;
    cin>>u>>v;
    u--;
    v--;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  set<P> st;
  for(ll i=0;i<n;i++){
    set<ll> seen;
    seen.insert(i);
    vector<ll> used;
    dfs(i,seen,0,used,G);
    for(ll u:used){
      st.insert(P(i,u));
      st.insert(P(u,i));
    }
  }
  cout<<st.size()/2<<endl;
}
0