QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#219647 | #5663. Tangle: A DAG for storing transactions | shen0628# | RE | 0ms | 0kb | C++17 | 2.7kb | 2023-10-19 17:05:25 | 2023-10-19 17:05:25 |
answer
// #pragma GCC optimize("03,unroll-loops")
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <bitset>
#include <set>
#include <unordered_set>
#include <utility>
#include <numeric>
#include <iomanip>
#include <stack>
#include <list>
#include <bitset>
#include <sstream>
#include <random>
#include <stdlib.h>
#include <time.h>
#define ll long long
#define ld long double
#define INF 0x3f3f3f3f
#define MXN 20005
#define cl(x) (x << 1)
#define cr(x) ((x << 1) | 1)
#define SZ(x) (int)x.size()
#define PB push_back
#define lowbit(x) (x & (-x))
#define NO_TAG false
#define P1 75577
#define P2 12721
#define MOD1 998244353
#define MOD2 1000000007
using namespace std;
// mt19937 gen(chrono::steady_clock::now().time_since_epoch().count());
// int rand_int(int lb, int ub) {
// return uniform_int_distribution<int>(lb, ub)(gen);
// }
int n, val;
vector<vector<int>> edge;
vector<int> vval;
vector<bool> vis;
vector<bitset<MXN>> bs;
void init() {
edge.clear();
edge.resize(n + 2);
vval.clear();
vval.resize(n + 2, 0);
vis.clear();
vis.resize(n + 2, false);
bs.clear();
bs.resize(n + 2);
}
void dfs(int x) {
vis[x] = true;
bs[x].set(x);
for(int i:edge[x]) {
if (vis[i]) {
continue;
}
dfs(i);
bs[x] |= bs[i];
}
}
void solve() {
// 靠邀,我頭很痛。
// 啊我微積分就退選,你覺得我看起來像會看懂題目的人嗎?
int n, val, res=0;
cin>>n>>val;
edge.clear();
edge.resize(n + 2);
init();
for (int i = 0, x, y, z, w; i < n; i++) {
cin >> x >> y >> z >> w;
edge[y].push_back(x);
edge[z].push_back(x);
vval[x] = w;
}
for (int i = 0; i < n + 2; i++) {
if (!vis[i]) {
dfs(i);
}
}
for (int i = 2; i < n + 2; i++) {
int v = 0;
for (int j = 2; j < n + 2; j++) {
if (bs[i].test(j)) {
v += vval[j];
}
}
if (v >= val) {
cout << i << " " << v << "\n";
res++;
}
}
cout << res << "\n";
return ;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
// cin >> t;
while (t--) {
solve();
}
return 0;
}
/*
5
TATCGATCGAGTTGT
TCCGCGAGCGAGTCTCTCCATT
GTTTCATCATACGAGGCCCCATACGCGCTGG
AGATGGGATCCTTATG
GCCCTTAGGCATGGGATGTCGTTTCTTG
*/
詳細信息
Test #1:
score: 0
Runtime Error
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