QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#577948 | #8943. Challenge Matrix Multiplication | skip2004 | WA | 4ms | 11804kb | C++20 | 1.6kb | 2024-09-20 15:37:49 | 2024-09-20 15:37:49 |
Judging History
answer
#include<bits/stdc++.h>
namespace rgs = std::ranges;
using std::cin, std::cout;
using ll = long long;
using u64 = unsigned long long;
using db = double;
const int N = 1000005;
int n, m;
std::vector<int> e[N], ee[N];
int in[N];
int vis[N], a[N], cc;
void dfs0(int x) {
vis[x] = 1;
for(int x : ee[x]) if(!vis[x]) {
dfs0(x);
}
a[++cc] = x;
}
int ans[N];
int max[N];
int label[N];
std::bitset<128> reach[N];
int main() {
std::ios::sync_with_stdio(false), cin.tie(0);
cin >> n >> m;
for(int i = 0, u, v;i < m;++i) {
cin >> u >> v;
e[u].push_back(v);
++ in[v];
}
std::queue<int> Q;
std::vector<int> o;
int cc = 0;
for(int i = 1;i <= n;++i) {
ee[i] = e[i];
if(in[i] != (int) e[i].size()) {
label[i] = ++cc;
reach[i].set(cc);
}
if(in[i] == 0) Q.push(i);
}
for(int i = 1;i <= n;++i) if(!vis[i]) {
dfs0(i);
}
for(;Q.size();) {
int x = Q.front(); Q.pop();
std::vector<int> list;
for(int i = x;;) {
list.push_back(i);
if(e[i].empty()) break;
int go = e[i].back();
e[i].pop_back();
i = go;
if(--in[i] == 0) Q.push(i);
}
for(int i = list.size() - 1, cnt = 0;i >= 0;--i) {
cnt += !label[list[i]];
max[list[i]] = cnt;
}
for(int i = 1;i <= n;++i) {
int x = a[i];
for(int u : ee[x]) {
max[x] = std::max(max[x], max[u]);
}
ans[x] += max[x];
}
}
for(int i = 1;i <= n;++i) {
int x = a[i];
for(int u : ee[x]) {
reach[x] |= reach[u];
}
ans[x] += reach[x].count();
}
for(int i = 1;i <= n;++i) {
cout << ans[i] << " \n"[i == n];
}
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 11744kb
input:
4 6 1 3 2 3 2 4 1 2 1 3 1 3
output:
4 3 1 1
result:
ok 4 number(s): "4 3 1 1"
Test #2:
score: 0
Accepted
time: 0ms
memory: 11804kb
input:
5 7 1 4 1 5 1 2 2 4 3 4 2 5 1 4
output:
4 3 2 1 1
result:
ok 5 number(s): "4 3 2 1 1"
Test #3:
score: -100
Wrong Answer
time: 4ms
memory: 11776kb
input:
100 900 89 90 34 35 45 46 97 98 41 42 59 61 19 20 25 29 2 3 28 29 54 55 77 78 69 74 60 61 43 44 13 14 92 93 65 66 68 69 72 73 78 81 54 56 55 60 14 15 9 10 92 93 10 11 18 19 16 17 97 98 76 77 39 40 71 72 7 8 63 64 7 8 16 24 13 24 83 84 90 91 1 4 4 5 96 97 81 82 91 92 80 81 66 67 19 20 3 4 9 10 47 48 ...
output:
50 49 48 47 46 45 44 43 43 42 41 40 39 38 37 37 36 36 36 36 36 36 36 36 36 36 36 35 34 33 32 31 30 29 29 28 27 27 26 26 25 24 24 24 24 24 24 24 24 24 24 24 24 23 23 23 23 23 23 22 21 20 19 18 17 16 15 14 13 12 12 12 12 12 12 12 12 12 12 12 12 12 12 12 11 10 9 9 9 9 9 8 7 7 6 5 4 3 2 1
result:
wrong answer 1st numbers differ - expected: '100', found: '50'