結果
| 問題 |
No.1002 Twotone
|
| コンテスト | |
| ユーザー |
tempura_pp
|
| 提出日時 | 2020-02-21 16:20:22 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,006 bytes |
| コンパイル時間 | 952 ms |
| コンパイル使用メモリ | 101,056 KB |
| 実行使用メモリ | 19,500 KB |
| 最終ジャッジ日時 | 2024-10-10 01:43:02 |
| 合計ジャッジ時間 | 9,501 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 5 TLE * 1 -- * 27 |
ソースコード
#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;
}
tempura_pp