Submission #1688504


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< VC > VCC;
typedef std::vector<int>  VI;
typedef std::vector< VI > VII;
typedef std::vector<long> VL;
typedef std::vector<long> VL;
typedef std::vector<long long> VLL;
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;

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

    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);

    int ans = 0;
    REP(i, N) {
        REP(j, N) {
            if(i >= j) continue;

            LL diff = values[i] ^ values[j];
            if(diff == X) {
                ans++;
            }
        }
    }
    std::cout << ans << std::endl;
}

Submission Info

Submission Time
Task C - エックスオア多橋君
User b1464296
Language C++14 (GCC 5.4.1)
Score 0
Code Size 2408 Byte
Status TLE
Exec Time 2104 ms
Memory 12672 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 100
Status
AC × 3
AC × 17
TLE × 10
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 3 ms 384 KB
subtask1_03.txt TLE 2104 ms 8448 KB
subtask1_04.txt TLE 2104 ms 8448 KB
subtask1_05.txt TLE 2104 ms 8448 KB
subtask1_06.txt TLE 2104 ms 12672 KB
subtask1_07.txt TLE 2104 ms 8448 KB
subtask1_08.txt TLE 2104 ms 8448 KB
subtask1_09.txt TLE 2104 ms 8448 KB
subtask1_10.txt TLE 2104 ms 8448 KB
subtask1_11.txt AC 3 ms 384 KB
subtask1_12.txt AC 3 ms 384 KB
subtask1_13.txt TLE 2103 ms 10496 KB
subtask1_14.txt TLE 2104 ms 8448 KB
subtask1_15.txt AC 97 ms 1024 KB
subtask1_16.txt AC 96 ms 1024 KB
subtask1_17.txt AC 96 ms 1024 KB
subtask1_18.txt AC 96 ms 1024 KB
subtask1_19.txt AC 96 ms 1024 KB
subtask1_20.txt AC 96 ms 1024 KB
subtask1_21.txt AC 96 ms 1024 KB
subtask1_22.txt AC 96 ms 1024 KB
subtask1_23.txt AC 96 ms 1024 KB
subtask1_24.txt AC 96 ms 1024 KB