QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#202478 | #6354. 4 | UrgantTeam | WA | 5ms | 14112kb | C++23 | 2.2kb | 2023-10-06 04:42:50 | 2023-10-06 04:42:50 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int const maxn = 1e5 + 5, K = 500;
vector < int > g[maxn], G[maxn];
unordered_set < int > in[maxn];
int pos[maxn];
bitset < K > go[K];
inline string sum(string a, string b) {
string res = "";
int ok = 0;
for (int i = 0; i < max(a.size(), b.size()); i++) {
if (i < a.size()) ok += (a[a.size() - i - 1] - '0');
if (i < b.size()) ok += (b[b.size() - i - 1] - '0');
res += char('0' + ok % 10);
ok /= 10;
}
if (ok) res += "1";
reverse(res.begin(), res.end());
return res;
}
main() {
#ifdef HOME
freopen("input.txt", "r", stdin);
#endif // HOME
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m, u, v;
cin >> n >> m;
for (int i = 1; i <= m; i++) {
cin >> u >> v;
g[u].push_back(v);
g[v].push_back(u);
}
vector < int > node;
for (int i = 1; i <= n; i++) node.push_back(i);
sort(node.begin(), node.end(), [](int u, int v) {
return g[u].size() < g[v].size();
});
for (int i = 0; i < n; i++) pos[node[i]] = i;
for (int i = 1; i <= n; i++) {
for (auto to : g[i]) {
if (pos[i] < pos[to]) G[i].push_back(to), in[i].insert(to);
}
}
string ans = "0";
for (int i = 0; i < n; i++) {
int cur = node[i];
assert(G[i].size() < K);
for (int j = 0; j < G[i].size(); j++) go[j] = 0;
sort(G[cur].begin(), G[cur].end(), [](int u, int v) {
return pos[u] < pos[v];
});
vector < pair < int, int > > edges;
for (int j = 0; j < G[cur].size(); j++) {
for (int z = j + 1; z < G[cur].size(); z++) {
if (in[G[cur][j]].find(G[cur][z]) != in[G[cur][j]].end()) {
go[j][z] = 1;
go[z][j] = 1;
edges.push_back({j, z});
}
}
}
ll add = 0;
for (auto [u, v] : edges) {
add += (go[u]&go[v]).count();
}
add /= 3;
if (add) ans = sum(ans, to_string(add));
//cout << cur << " " << ans << endl;
}
cout << ans << '\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 13756kb
input:
5 9 1 2 1 3 1 4 1 5 2 3 2 4 2 5 3 4 3 5
output:
2
result:
ok 1 number(s): "2"
Test #2:
score: 0
Accepted
time: 0ms
memory: 13952kb
input:
4 0
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: 0
Accepted
time: 0ms
memory: 13840kb
input:
50 50 28 35 12 24 31 50 10 24 21 44 5 31 23 36 31 45 6 39 4 8 13 37 42 48 17 45 19 33 12 21 19 32 16 43 12 47 25 31 40 48 8 49 43 48 6 42 27 34 13 39 17 40 13 35 3 49 20 24 5 12 43 44 15 37 24 27 8 43 4 22 17 38 28 47 29 46 3 15 9 49 1 41 43 45 3 6 37 48 13 30 11 43 8 25 33 38 16 32 32 41
output:
0
result:
ok 1 number(s): "0"
Test #4:
score: -100
Wrong Answer
time: 5ms
memory: 14112kb
input:
100 4900 64 78 3 13 93 96 48 64 34 64 5 76 66 74 44 78 17 20 30 73 5 34 24 100 23 65 4 70 22 95 47 70 6 89 15 70 70 82 88 90 29 80 27 64 16 59 28 99 67 68 85 99 37 85 8 46 71 78 40 95 6 21 27 66 16 89 11 83 17 57 19 36 21 70 27 86 27 45 5 56 10 64 23 33 87 91 37 40 21 55 75 79 54 96 3 77 70 78 36 93...
output:
3719150
result:
wrong answer 1st numbers differ - expected: '3689634', found: '3719150'