Submission #9591220
Source Code Expand
#include <cstdio> #include <vector> #include <algorithm> using namespace std; typedef long long ll; const int MAXN = 1000; const int MAXM = 2000; const int MOD = int(1E9) + 7; int pw2[MAXM + 5]; void init() { pw2[0] = 1; for(int i=1;i<=MAXM;i++) pw2[i] = 2LL*pw2[i-1]%MOD; } struct edge{ int u, v; ll w; friend bool operator < (const edge &a, const edge &b) { return a.w < b.w; } }e[MAXM + 5], t[MAXM + 5]; ll G[MAXN + 5][MAXN + 5]; int fa[MAXN + 5]; vector<int>v[MAXN + 5]; int find(int x) { return (x == fa[x] ? x : find(fa[x])); } bool merge(int x, int y, ll w) { if( find(x) == find(y) ) return false; x = find(x), y = find(y); if( v[x].size() > v[y].size() ) swap(x, y); for(int i=0;i<v[x].size();i++) for(int j=0;j<v[y].size();j++) G[v[x][i]][v[y][j]] = G[v[y][j]][v[x][i]] = w; fa[x] = y; for(int i=0;i<v[x].size();i++) v[y].push_back(v[x][i]); return true; } int main() { init(); int N, M; ll X; scanf("%d%d%lld", &N, &M, &X); for(int i=1;i<=M;i++) scanf("%d%d%lld", &e[i].u, &e[i].v, &e[i].w); sort(e + 1, e + M + 1); for(int i=1;i<=N;i++) fa[i] = i, v[i].push_back(i); ll A = 0; int cnt = 0; for(int i=1;i<=M;i++) { if( !merge(e[i].u, e[i].v, e[i].w) ) t[++cnt] = e[i], t[cnt].w -= G[e[i].u][e[i].v]; else A += e[i].w; } int ans = 0; if( A == X ) ans = (pw2[M] + MOD - pw2[M-N+1+1]) % MOD; sort(t + 1, t + cnt + 1); for(int i=1;i<=cnt;i++) if( A + t[i].w == X ) ans = (ans + pw2[cnt-i+1]) % MOD; printf("%d\n", ans); }
Submission Info
Submission Time | |
---|---|
Task | E - Bichrome Spanning Tree |
User | vjudge1 |
Language | C++14 (GCC 5.4.1) |
Score | 900 |
Code Size | 1484 Byte |
Status | AC |
Exec Time | 11 ms |
Memory | 8320 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:49:31: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d%d%lld", &N, &M, &X); ^ ./Main.cpp:51:47: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d%d%lld", &e[i].u, &e[i].v, &e[i].w); ^
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 900 / 900 | ||||
Status |
|
|
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 | AC | 10 ms | 8192 KB |
02.txt | AC | 11 ms | 8192 KB |
03.txt | AC | 11 ms | 8192 KB |
04.txt | AC | 10 ms | 8192 KB |
05.txt | AC | 11 ms | 8320 KB |
06.txt | AC | 11 ms | 8192 KB |
07.txt | AC | 10 ms | 8192 KB |
08.txt | AC | 11 ms | 8192 KB |
09.txt | AC | 10 ms | 8192 KB |
10.txt | AC | 10 ms | 8192 KB |
11.txt | AC | 11 ms | 8192 KB |
12.txt | AC | 10 ms | 8192 KB |
13.txt | AC | 10 ms | 8192 KB |
14.txt | AC | 10 ms | 8192 KB |
15.txt | AC | 11 ms | 8192 KB |
16.txt | AC | 11 ms | 8192 KB |
17.txt | AC | 11 ms | 8192 KB |
18.txt | AC | 10 ms | 8192 KB |
19.txt | AC | 10 ms | 8192 KB |
20.txt | AC | 10 ms | 8192 KB |
21.txt | AC | 10 ms | 8192 KB |
22.txt | AC | 10 ms | 8192 KB |
23.txt | AC | 10 ms | 8192 KB |
24.txt | AC | 10 ms | 8192 KB |
25.txt | AC | 10 ms | 8192 KB |
26.txt | AC | 11 ms | 8192 KB |
27.txt | AC | 11 ms | 8192 KB |
28.txt | AC | 10 ms | 8192 KB |
29.txt | AC | 10 ms | 8192 KB |
30.txt | AC | 10 ms | 8192 KB |
31.txt | AC | 10 ms | 8192 KB |
32.txt | AC | 10 ms | 8192 KB |
33.txt | AC | 10 ms | 8192 KB |
34.txt | AC | 11 ms | 8192 KB |
35.txt | AC | 2 ms | 768 KB |
36.txt | AC | 2 ms | 640 KB |
37.txt | AC | 2 ms | 640 KB |
38.txt | AC | 11 ms | 8192 KB |
39.txt | AC | 10 ms | 8192 KB |
40.txt | AC | 10 ms | 8192 KB |
41.txt | AC | 11 ms | 8192 KB |
42.txt | AC | 10 ms | 8192 KB |
43.txt | AC | 10 ms | 8192 KB |
44.txt | AC | 10 ms | 8192 KB |
45.txt | AC | 10 ms | 8192 KB |
46.txt | AC | 10 ms | 8192 KB |
47.txt | AC | 10 ms | 8192 KB |
48.txt | AC | 11 ms | 8192 KB |
sample-01.txt | AC | 1 ms | 256 KB |
sample-02.txt | AC | 1 ms | 256 KB |
sample-03.txt | AC | 1 ms | 256 KB |
sample-04.txt | AC | 1 ms | 256 KB |