QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#102675 | #5663. Tangle: A DAG for storing transactions | Joler# | WA | 2ms | 5468kb | C++14 | 1.8kb | 2023-05-03 15:52:55 | 2023-05-03 15:52:58 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#ifdef LOCAL
template<class t,class u>ostream& operator<<(ostream& os,const pair<t,u>& p){return os<<"("<<p.first<<","<<p.second<<")";}
#endif
template<class t>ostream& operator<<(ostream& os,const vector<t>& v){if(v.size())os<<v[0];for(int i=1; i<v.size(); i++)os<<' '<<v[i]; return os;}
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
int n, m, t, k, a, b, c, d, cnt, mark, an, oT_To, x, y, z;
ll ans;
short val[10005], vis[10005];
int sum[10005];
bitset<10005> bs[10005];
vector <int> ve[10005];
vector <pair<int, int> > vans;
void dfs(int x) {
for (int nxt : ve[x]) {
if (vis[nxt]) {
bs[x] |= bs[nxt];
continue;
}
vis[nxt] = 1;
dfs(nxt);
bs[x] |= bs[nxt];
}
bs[x][x] = 1;
for (int i = 2; i <= n+1; ++i) {
if (bs[x][i]) sum[x] += val[i];
}
if (x >= 2 && sum[x] >= k) {
vans.push_back({sum[x], x});
}
}
struct Solver {
void solve() {
cin >> n >> k;
for (int i = 0; i < n; ++i) {
cin >> a >> b >> c >> d;
val[a] = d;
ve[b].push_back(a);
ve[c].push_back(a);
}
ve[0].push_back(1);
vis[0] = 1;
dfs(0);
// for (int i = 0; i <= n+1; ++i) {
// cout << "sum["<<i<<"]: " << sum[i] << '\n';
// }
sort(vans.rbegin(), vans.rend());
for (const auto&[y, x] : vans) {
cout << x << ' ' << y << '\n';
}
cout << vans.size();
}
};
int main () {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
oT_To = 1;
// cin >> oT_To;
while (oT_To--) {
Solver solver;
solver.solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5468kb
input:
6 12 2 0 1 3 3 0 2 2 4 1 2 1 5 2 3 3 6 3 4 4 7 3 5 5
output:
2 18 3 14 2
result:
ok 3 lines
Test #2:
score: -100
Wrong Answer
time: 2ms
memory: 3628kb
input:
21 20 2 0 1 2 3 1 0 5 4 1 0 2 5 2 1 1 6 1 3 1 7 5 4 1 8 3 7 5 9 2 4 1 10 4 9 1 11 9 4 5 12 4 8 2 13 3 12 2 14 2 10 5 15 11 12 4 16 3 9 2 17 1 16 4 18 0 7 3 19 11 5 2 20 14 4 5 21 19 5 2 22 18 9 4
output:
2 51 4 50 9 35 5 26 3 25 7 21 6
result:
wrong answer 2nd lines differ - expected: '3 25', found: '4 50'