Submission #1688722


Source Code Expand

#include<bits/stdc++.h>

// Shrotening
#define fst first
#define snd second
#define pb push_back

// Loop
#define FOR(i,a,b) for(long i=(a);i<(b);++i)
#define RFOR(i,a,b) for(long i=(a);i>=(b);--i)

#define REP(i,a) FOR(i,0,a)
#define RREP(i,a) RFOR(i,a,0)

#define EACH(i,a) for(auto (i)=(a).begin(),_END=(a).end();i!=_END;++i)
#define REACH(i,a) for(auto (i)=(a).rbegin(),_END=(a).rend();i!=_END;++i)

//Algorithm
#define ALL(a) (a).begin(), a.end()
#define RALL(a) (a).rbegin(), a.rend()
#define EXIST(a,x) ((a).find(x)!=(a).end())
#define SORT(a) sort(ALL(a))
#define UNIQUE(a) SORT(a), a.erase(std::unique(ALL(a)), a.end());

//Setting
#define OPT std::cin.tie(0);std::ios::sync_with_stdio(false);

//debug message
bool debug = true;
#define MSG(s)   if(debug){std::cout << s << std::endl;}
#define DEBUG(x) if(debug){std::cout << "debug(" << #x << "): " << x << std::endl;}

//alias
typedef long long LL;
typedef std::vector<char> VC;
typedef std::vector<int>  VI;
typedef std::vector<long> VL;
typedef std::vector<long long> VLL;

typedef std::vector< VC > VCC;
typedef std::vector< VI > VII;

typedef std::pair<int,int> PII;

typedef long long Weight;
const Weight WEIGHT_INF = std::numeric_limits<Weight>::max()/4;
struct Edge {
    int src, dst;
    Weight weight;
};
bool operator<(const Edge& a, const Edge& b) {
    return (a.weight < b.weight);
};
bool operator>(const Edge& a, const Edge& b) {
    return (a.weight > b.weight);
};
typedef std::vector<Edge> Edges;
typedef std::vector<Edges> Graph;

int N, X;
Graph g;
VLL values;
std::map<LL, LL> table;

LL ans;
void dfs(int i, int p, LL v) {
    if(values[i] != -1) return;

    ans += table[v ^ X];
    table[v]++;

    values[i] = v;
    EACH(it, g[i]) {
        if(p != it->dst) {
            dfs(it->dst, i, v ^ it->weight);
        }
    }
}

int main() {
    std::cin >> N >> X;
    g.resize(N);
    values.resize(N, -1);

    int x, y, c;
    REP(i, N-1) {
        std::cin >> x >> y >> c;
        x--, y--;
        Edge e1{x, y, c};
        Edge e2{y, x, c};
        g[x].pb(e1);
        g[y].pb(e2);
    }
    dfs(0, -1, 0ll);

    std::cout << ans << std::endl;
}

Submission Info

Submission Time
Task C - エックスオア多橋君
User b1464296
Language C++14 (GCC 5.4.1)
Score 100
Code Size 2236 Byte
Status AC
Exec Time 240 ms
Memory 20992 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 100 / 100
Status
AC × 3
AC × 27
Set Name Test Cases
Sample subtask0_sample_01.txt, subtask0_sample_02.txt, subtask0_sample_03.txt
All subtask0_sample_01.txt, subtask0_sample_02.txt, subtask0_sample_03.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask1_08.txt, subtask1_09.txt, subtask1_10.txt, subtask1_11.txt, subtask1_12.txt, subtask1_13.txt, subtask1_14.txt, subtask1_15.txt, subtask1_16.txt, subtask1_17.txt, subtask1_18.txt, subtask1_19.txt, subtask1_20.txt, subtask1_21.txt, subtask1_22.txt, subtask1_23.txt, subtask1_24.txt
Case Name Status Exec Time Memory
subtask0_sample_01.txt AC 1 ms 256 KB
subtask0_sample_02.txt AC 1 ms 256 KB
subtask0_sample_03.txt AC 1 ms 256 KB
subtask1_01.txt AC 1 ms 256 KB
subtask1_02.txt AC 2 ms 384 KB
subtask1_03.txt AC 239 ms 20992 KB
subtask1_04.txt AC 232 ms 20992 KB
subtask1_05.txt AC 240 ms 20992 KB
subtask1_06.txt AC 109 ms 15872 KB
subtask1_07.txt AC 121 ms 8448 KB
subtask1_08.txt AC 118 ms 8448 KB
subtask1_09.txt AC 162 ms 9472 KB
subtask1_10.txt AC 157 ms 9472 KB
subtask1_11.txt AC 2 ms 384 KB
subtask1_12.txt AC 2 ms 384 KB
subtask1_13.txt AC 139 ms 8576 KB
subtask1_14.txt AC 135 ms 8576 KB
subtask1_15.txt AC 17 ms 1792 KB
subtask1_16.txt AC 17 ms 1792 KB
subtask1_17.txt AC 16 ms 1792 KB
subtask1_18.txt AC 17 ms 1792 KB
subtask1_19.txt AC 16 ms 1792 KB
subtask1_20.txt AC 16 ms 1792 KB
subtask1_21.txt AC 16 ms 1792 KB
subtask1_22.txt AC 17 ms 1792 KB
subtask1_23.txt AC 16 ms 1792 KB
subtask1_24.txt AC 17 ms 1792 KB