結果
| 問題 |
No.439 チワワのなる木
|
| ユーザー |
nanophoto12
|
| 提出日時 | 2016-11-05 12:09:25 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,975 bytes |
| コンパイル時間 | 741 ms |
| コンパイル使用メモリ | 94,952 KB |
| 実行使用メモリ | 31,016 KB |
| 最終ジャッジ日時 | 2024-11-25 03:04:23 |
| 合計ジャッジ時間 | 2,323 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 4 WA * 24 |
ソースコード
#include <cmath>
#include <vector>
#include <map>
#include <functional>
#include <queue>
#include <iostream>
#include <string.h>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <cstdint>
#include <climits>
#include <unordered_set>
#include <sstream>
using namespace std;
#define ll long long int
#define ti4 tuple<int,int,int,int>
#define pii pair<ll,ll>
#define REP(x,n) for(int x = 0;x < n;x++)
struct UnionFind {
vector<ll> data;
UnionFind(ll size) : data(size, -1) { }
bool unionSet(ll x, ll y) {
x = root(x); y = root(y);
if (x != y) {
if (data[y] < data[x]) swap(x, y);
data[x] += data[y]; data[y] = x;
}
return x != y;
}
bool findSet(ll x, ll y) {
return root(x) == root(y);
}
ll root(ll x) {
return data[x] < 0 ? x : data[x] = root(data[x]);
}
ll size(ll x) {
return -data[root(x)];
}
};
bool cw[1000001];
vector<int> v[1000001];
int main()
{
int n;
cin >> n;
string ss;
cin >> ss;
for(int i = 0;i < n;i++)
{
if(ss[i] == 'c')
{
cw[i] = true;
}
else
{
cw[i] = false;
}
}
vector<int> start;
for(int i = 0;i < n-1;i++)
{
int a,b;
cin >> a >> b;
a--;
b--;
bool f = cw[a];
bool t = cw[b];
if(f)
{
start.push_back(a);
if(!t)
{
v[a].push_back(b);
}
}
else if(t)
{
start.push_back(b);
v[b].push_back(a);
}
else
{
v[a].push_back(b);
v[b].push_back(a);
}
}
ll sum = 0;
for(auto e : start)
{
const vector<int>& second = v[e];
for(auto t : second)
{
sum += v[t].size();
}
}
cout << sum << endl;
return 0;
}
nanophoto12