zoukankan      html  css  js  c++  java
  • Tenka1 Programmer Contest 2019 E

    题目链接

    参考博客

    关于check()函数,相隔p-1取出来,提出一个公因数后,剩下的为(x^{p-1},x^{2*(p-1)}…x^{n*(p-1)}),x与p互质,各项的幂取余p的欧拉函数为0。

    #include "bits/stdc++.h"
     
    using namespace std;
    typedef long long ll;
    const int mod = 1e9 + 7;
    const int maxn = 1e6 + 100;
    const int inf = 0x3f3f3f3f;
     
    vector<pair<int, int> > e[maxn];
     
    int n, k;
    int vis[maxn];
    int xorr[maxn];
     
    void read(int &x) {
        x = 0;
        char ch, c = getchar();
        while (c < '0' || c > '9') ch = c, c = getchar();
        while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
        if (ch == '-') x = -x;
    }
     
    void dfs(int now) {
        if (vis[now]) return;
        vis[now] = 1;
        for (auto x:e[now]) {
            if (!vis[x.first]) {
                xorr[x.first] = xorr[now] ^ x.second;
                dfs(x.first);
            }
        }
    }
     
    unordered_map<int, int> mp;
     
    int main() {
       // freopen("in.txt", "r", stdin);
        read(n);
        read(k);
        int x, y, z;
        for (int i = 1; i < n; i++) {
            read(x);
            read(y);
            read(z);
            e[x].push_back({y, z});
            e[y].push_back({x, z});
        }
        dfs(1);
        for (int i = 1; i <= n; i++) {
            mp[xorr[i]]++;
        }
        ll ans = 0;
        for (int i = 1; i <= n; i++) {
            mp[xorr[i]]--;
            x = xorr[i] ^ k;
            ans += mp[x];
            mp[xorr[i]]++;
        }
        cout << ans / 2 << endl;
        return 0;
    }
    
  • 相关阅读:
    idea 快捷键
    上传代码
    maven 打包
    mysql 通过测试'for update',深入了解行锁、表锁、索引
    mysql中,手动提交事务
    java 发送邮件
    zk脑裂
    malloc,free和new,delete之间的区别
    sizeof和strlen区别
    字符串常量问题
  • 原文地址:https://www.cnblogs.com/albert-biu/p/11265989.html
Copyright © 2011-2022 走看看