QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#511439 | #7895. Graph Partitioning 2 | JEdward | WA | 39ms | 12124kb | C++17 | 1.8kb | 2024-08-09 21:32:34 | 2024-08-09 21:32:35 |
Judging History
answer
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0), cin.tie(0)
#define int long long
#define endl '\n'
#define lowbit(x) (x)&(-x)
#define pii pair<int,int>
#define all(s) s.begin(), s.end()
#define ls(x) (x<<1)
#define rs(x) (x<<1|1)
#define here system("pause")
using namespace std;
template <class T> inline void read(T& x) { x = 0; char c = getchar(); bool f = 0; for (; !isdigit(c); c = getchar()) f ^= (c == '-'); for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + (c ^ 48); x = f ? -x : x; }
template <class T> inline void write(T x) { if (x < 0) putchar('-'), x = -x; if (x < 10) putchar(x + 48); else write(x / 10), putchar(x % 10 + 48); }
const int N = 1e5+5;
const int mod = 1e9+7;
const int INF = 8e18+7;
const double eps = 1e-6;
inline int pow(int a, int b, int p){ int res = 1%p; while(b){ if(b&1) res=res*a%p; a=a*a%p, b>>=1;} return res;}
inline int inv(int a, int p){ return pow(a,p-2,p)%p;}
int n, k;
vector<int> g[N];
unordered_map<int,int> f[N], mp;
inline void dfs(int u, int fa){
f[u][1] = 1;
for(int v:g[u]){
if(v==fa) continue;
dfs(v, u);
for(auto x:f[u]){
for(auto y:f[v]){
if(x.second == 0 || y.second == 0) continue;
if(x.first + y.first <= k+1){
mp[x.first + y.first] = (mp[x.first + y.first] + x.second * y.second % mod) % mod;
}
}
}
swap(f[u], mp);
mp.clear();
}
f[u][0] = (f[u][0] + f[u][k] + f[u][k+1]) % mod;
f[u][k+1] = 0;
}
inline void sol(){
cin >> n >> k;
for(int i=1;i<=n;i++){
g[i].clear();
f[i].clear();
}
for(int i=1;i<n;i++){
int u, v;
cin >> u >> v;
g[u].push_back(v);
g[v].push_back(u);
}
dfs(1, 0);
cout << f[1][0] << endl;
}
signed main(){
IOS;
int tc = 1;
cin >> tc;
while(tc--){
sol();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 3ms
memory: 11356kb
input:
2 8 2 1 2 3 1 4 6 3 5 2 4 8 5 5 7 4 3 1 2 1 3 2 4
output:
2 1
result:
ok 2 lines
Test #2:
score: -100
Wrong Answer
time: 39ms
memory: 12124kb
input:
5550 13 4 10 3 9 1 10 8 3 11 8 5 10 7 9 6 13 5 9 7 2 7 5 12 4 8 8 2 4 1 3 4 7 8 2 5 6 7 4 8 2 3 11 1 11 10 1 4 9 10 8 4 3 6 5 7 6 1 10 2 11 7 11 1 17 2 14 16 13 15 17 3 15 11 1 6 13 2 13 17 4 8 14 10 8 14 14 5 9 12 14 2 12 17 17 6 15 7 14 6 2 14 2 13 2 4 8 4 3 11 7 3 14 1 11 9 13 3 5 10 6 8 3 10 14 ...
output:
0 3 112 0 1 0 1 0 0 0 1 0 1 0 0 1 0 140 0 0 0 814 1 6 1 1 2 2 0 612 0 1 0 0 0 1 1 0 0 121 4536 0 0 1718 0 0 1 0 444 1 1908 1813 3 74 0 1 0 46 0 0 0 0 0 0 0 0 0 1 0 1 1 1 239 0 0 0 1 0 0 0 1 0 1 0 0 1 1 0 0 0 1 0 0 0 48 0 2 0 0 0 1 364 0 206 0 0 76 0 1 0 0 2 0 1 2 0 0 1 0 0 4 0 1 1 0 0 1 1 1 0 0 1 1 ...
result:
wrong answer 5004th lines differ - expected: '224400650', found: '910039701'