QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#625472 | #8943. Challenge Matrix Multiplication | ucup-team1264 | WA | 0ms | 3652kb | C++20 | 2.2kb | 2024-10-09 19:27:54 | 2024-10-09 19:27:54 |
Judging History
answer
// https://www.youtube.com/watch?v=CrymicX875M
// Angel of mercy
// How did you move me
// Why am I on my feet again
#ifndef ONLINE_JUDGE
#include "templates/debug.hpp"
#else
#define debug(...)
#endif
#include <bits/stdc++.h>
using namespace std;
using i64 = int64_t;
using u64 = uint64_t;
// #define int i64
void solve() {
int n, m; cin >> n >> m;
vector<vector<int>> adj(n), nadj;
vector<int> indeg(n, 0);
for (int e = 0; e < m; e++) {
int u, v; cin >> u >> v;
u--, v--;
adj[u].push_back(v);
indeg[v]++;
}
nadj = adj;
// split to at most 60 paths
vector<vector<int>> paths;
queue<int> q;
for (int i = 0; i < n; i++) {
if (indeg[i] == 0) {
q.push(i);
}
}
while (!q.empty()) {
int u = q.front(); q.pop();
while (adj[u].size()) {
vector<int> path;
function<void(int)> dfs = [&](int u) {
if (adj[u].empty()) {
path.push_back(u);
return;
}
int v = adj[u].back();
adj[u].pop_back();
if (!--indeg[v]) {
q.push(v);
}
dfs(v);
path.push_back(u);
};
dfs(u);
paths.push_back(path);
}
}
debug(paths);
assert(paths.size() <= 60);
vector<int> ans(n, 0);
vector<uint8_t> vis(n, 0);
vis.clear();
for (const auto& path : paths) {
int cnt = 0;
for (int u: path) {
q.push(u);
while (!q.empty()) {
int u = q.front(); q.pop();
for (int v : nadj[u]) {
if (!vis[v]) {
cnt++;
vis[v] = 1;
q.push(v);
}
}
}
ans[u] = cnt;
}
}
for (int x: ans) cout << x + 1 << " ";
cout << "\n";
}
#undef int
// Make bold hypotheses and verify carefully
int main() {
cin.tie(nullptr);
ios::sync_with_stdio(false);
int t = 1;
// cin >> t;
while (t--) {
solve();
};
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3652kb
input:
4 6 1 3 2 3 2 4 1 2 1 3 1 3
output:
1 1 1 1
result:
wrong answer 1st numbers differ - expected: '4', found: '1'