結果

問題 No.1002 Twotone
ユーザー tempura_pptempura_pp
提出日時 2020-02-21 16:20:22
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,006 bytes
コンパイル時間 997 ms
コンパイル使用メモリ 99,832 KB
実行使用メモリ 17,920 KB
最終ジャッジ日時 2024-04-18 08:30:16
合計ジャッジ時間 9,472 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
8,320 KB
testcase_01 AC 6 ms
8,192 KB
testcase_02 AC 6 ms
8,192 KB
testcase_03 AC 311 ms
14,464 KB
testcase_04 AC 386 ms
16,000 KB
testcase_05 AC 389 ms
16,280 KB
testcase_06 AC 4 ms
8,320 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 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int cnt[202020];
vector<pair<int,int>> v[202020];
ll ans;
void dfs(int x, int p, int c){
    if(c==2)++ans;
    for(auto to:v[x]){
        if(to.first==p)continue;
        if(++cnt[to.second]==1)++c;
        if(c<=2)dfs(to.first,x,c);
        if(--cnt[to.second]==0)--c;
    }
}
int main(){
    int n,k;
    cin>>n>>k;
    rep(i,n-1){
        int x,y,z;
        cin>>x>>y>>z;
        --x;--y;
        v[x].emplace_back(y,z);
        v[y].emplace_back(x,z);
    }
    rep(i,n)dfs(i,-1,0);
    cout<<ans/2<<endl;
    return 0;
}
0