結果
問題 | No.2638 Initial fare |
ユーザー | ramdos |
提出日時 | 2024-02-11 14:06:54 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,258 bytes |
コンパイル時間 | 2,269 ms |
コンパイル使用メモリ | 212,428 KB |
実行使用メモリ | 28,320 KB |
最終ジャッジ日時 | 2024-02-11 14:08:39 |
合計ジャッジ時間 | 31,684 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,676 KB |
testcase_01 | AC | 2 ms
6,676 KB |
testcase_02 | AC | 2 ms
6,676 KB |
testcase_03 | AC | 2 ms
6,676 KB |
testcase_04 | AC | 8,373 ms
19,516 KB |
testcase_05 | AC | 9,020 ms
20,396 KB |
testcase_06 | AC | 2 ms
6,676 KB |
testcase_07 | TLE | - |
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 | -- | - |
ソースコード
//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; }