Submission #5032160


Source Code Expand

#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<double> VD;
typedef vector<VD> VVD;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

struct union_find{
    VI par, sz;

    void init(int n){
        par.resize(n);
        sz.assign(n, 1);
        REP(i,n) par[i] = i;
    }

    int find(int x){
        if (par[x] == x) return x;
        else return par[x] = find(par[x]);
    }

    bool same(int x, int y){
        return find(x) == find(y);
    }

    void merge(int x, int y){
        x = find(x);
        y = find(y);
        if (x == y) return;
        par[x] = y;
        sz[y] += sz[x];
    }

    int size(int x){
        return sz[find(x)];
    }
};


const ll mod = 1000000007;

ll add(ll x, ll y){
    return (x+y)%mod;
}

ll mul(ll x, ll y){
    return (x%mod)*(y%mod)%mod;
}

ll powll(ll x, ll y){
    ll res = 1LL;
    while(y){
        if (y & 1LL)
            res *= x;
        res %= mod;
        x = (x*x) % mod;
        y >>= 1LL;
    }
    return res;
}

int main() {
    ll n, m, x;
    cin >> n >> m >> x;
    vector<pair<ll, P>> tmp(m);
    REP(i,m){
        ll u = in() - 1, v = in() - 1, w = in();
        tmp[i] = make_pair(w, P(u, v));
    }
    sort(ALL(tmp));
    VI u(m), v(m);
    VL w(m);
    REP(i,m){
        u[i] = tmp[i].second.first;
        v[i] = tmp[i].second.second;
        w[i] = tmp[i].first;
    }

    VI used(m);
    ll s = 0, p = 0;
    union_find uf;
    uf.init(n);
    REP(i,m){
        int j = i;
        while (j < m && w[j] == w[i]) j++;
        ll pp = p;
        FOR(k,i,j-1){
            if (!uf.same(u[k], v[k])) p++;
        }
        FOR(k,i,j-1){
            if (!uf.same(u[k], v[k])){
                uf.merge(u[k], v[k]);
                s += w[k];
                pp++;
            }
        }
        if (pp == n - 1){
            break;
        }
        p = pp;
        i = j - 1;
    }

    if (s > x){
        cout << 0 << endl;
        return 0;
    }

    if (s == x){
        ll ans = (powll(2, p) - 2) * powll(2, m - p);
        ans = ((ans % mod) + mod) % mod;
        cout << ans << endl;
        return 0;
    }

    cout << 1 / 0 << endl;

    return 0;
}

Submission Info

Submission Time
Task E - Bichrome Spanning Tree
User TangentDay
Language C++14 (GCC 5.4.1)
Score 0
Code Size 2940 Byte
Status RE
Exec Time 102 ms
Memory 384 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:145:15: warning: division by zero [-Wdiv-by-zero]
     cout << 1 / 0 << endl;
               ^
./Main.cpp: In function ‘int in()’:
./Main.cpp:34:34: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
 int in() { int x; scanf("%d", &x); return x; }
                                  ^
./Main.cpp: In function ‘ll lin()’:
./Main.cpp:35:35: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
 ll lin() { ll x; scanf("%lld", &x); return x; }
                                   ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 900
Status
AC × 2
RE × 2
AC × 7
WA × 3
RE × 42
Set Name Test Cases
Sample sample-01.txt, sample-02.txt, sample-03.txt, sample-04.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, 35.txt, 36.txt, 37.txt, 38.txt, 39.txt, 40.txt, 41.txt, 42.txt, 43.txt, 44.txt, 45.txt, 46.txt, 47.txt, 48.txt, sample-01.txt, sample-02.txt, sample-03.txt, sample-04.txt
Case Name Status Exec Time Memory
01.txt RE 99 ms 256 KB
02.txt RE 98 ms 256 KB
03.txt RE 98 ms 256 KB
04.txt RE 97 ms 256 KB
05.txt RE 97 ms 256 KB
06.txt RE 101 ms 256 KB
07.txt RE 99 ms 256 KB
08.txt RE 98 ms 256 KB
09.txt RE 98 ms 256 KB
10.txt RE 97 ms 256 KB
11.txt RE 97 ms 256 KB
12.txt RE 98 ms 256 KB
13.txt RE 98 ms 256 KB
14.txt AC 2 ms 256 KB
15.txt WA 2 ms 384 KB
16.txt AC 2 ms 384 KB
17.txt WA 2 ms 384 KB
18.txt AC 2 ms 384 KB
19.txt RE 99 ms 256 KB
20.txt AC 2 ms 256 KB
21.txt WA 2 ms 384 KB
22.txt RE 97 ms 256 KB
23.txt RE 101 ms 256 KB
24.txt RE 98 ms 256 KB
25.txt RE 99 ms 256 KB
26.txt RE 97 ms 256 KB
27.txt RE 98 ms 256 KB
28.txt RE 98 ms 256 KB
29.txt RE 97 ms 256 KB
30.txt RE 97 ms 256 KB
31.txt RE 98 ms 256 KB
32.txt RE 98 ms 256 KB
33.txt RE 98 ms 256 KB
34.txt RE 97 ms 256 KB
35.txt RE 97 ms 256 KB
36.txt RE 98 ms 256 KB
37.txt RE 99 ms 256 KB
38.txt RE 99 ms 256 KB
39.txt RE 99 ms 256 KB
40.txt RE 99 ms 256 KB
41.txt RE 102 ms 256 KB
42.txt RE 97 ms 256 KB
43.txt RE 99 ms 256 KB
44.txt AC 2 ms 256 KB
45.txt RE 97 ms 256 KB
46.txt RE 97 ms 256 KB
47.txt RE 97 ms 256 KB
48.txt RE 97 ms 256 KB
sample-01.txt AC 1 ms 256 KB
sample-02.txt RE 97 ms 256 KB
sample-03.txt AC 1 ms 256 KB
sample-04.txt RE 97 ms 256 KB