QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#780813 | #9810. Obliviate, Then Reincarnate | hhhyh# | WA | 327ms | 63820kb | C++23 | 5.3kb | 2024-11-25 13:25:39 | 2024-11-25 13:25:40 |
Judging History
This is the latest submission verdict.
- [2024-11-26 23:19:26]
- hack成功,自动添加数据
- (/hack/1260)
- [2024-11-25 13:25:39]
- Submitted
answer
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define all(x) x.begin(), x.end()
#define int long long
void solve()
{
int n, m, q;
cin >> n >> m >> q;
vector<int> f(n), ok(n, 1);
iota(all(f), 0ll);
auto find = [&](auto find, int x) -> int
{
return f[x] == x ? f[x] : f[x] = find(find, f[x]);
};
vector<int> in(n), out(n);
vector<vector<pair<int, int>>> e(n);
vector<vector<pair<int, int>>> g(n);
for (int i = 0; i < m; i++)
{
int a, b;
cin >> a >> b;
int w = b;
a = (a % n + n) % n;
if (b == 0)
continue;
b = (b % n + n) % n;
b = (b + a) % n;
e[a].push_back({b, w});
g[b].push_back({a, w});
in[b]++;
out[a]++;
}
{
queue<int> q;
for (int i = 0; i < n; i++)
{
if (in[i] == 0 || out[i] == 0)
{
q.push(i);
}
}
while (!q.empty())
{
int x = q.front();
q.pop();
ok[x] = 0;
for (auto [y, w] : g[x])
{
out[y]--;
if (out[y] == 0)
{
q.push(y);
}
}
for (auto [y, w] : e[x])
{
in[y]--;
if (in[y] == 0)
{
q.push(y);
}
}
}
vector<vector<int>> p(n);
for (int i = 0; i < n; i++)
{
for (auto [y, w] : e[i])
{
if (ok[i] && ok[y])
{
int a = find(find, i), b = find(find, y);
f[b] = a;
}
}
}
for (int i = 0; i < n; i++)
{
if (ok[i])
p[find(find, i)].push_back(i);
}
vector<vector<int>> fa(n, vector<int>(21, -1));
vector<int> dep(n, -1);
vector<i64> val(n), vis(n);
for (int i = 0; i < n; i++)
{
if (p[i].empty())
continue;
int rt = -1;
auto dfs2 = [&](auto self, int x) -> void
{
int cnt = 0;
vis[x] = 1;
for (auto [y, w] : g[x])
{
if (!ok[y])
continue;
if (vis[y])
continue;
self(self, y);
cnt++;
}
if (cnt == 0 && rt == -1)
rt = x;
};
dfs2(dfs2, p[i][0]);
dep[rt] = 0;
int cnt = 0;
vector<array<int, 3>> edges;
function<void(int x, int fa)> dfs = [&](int x, int f)
{
fa[x][0] = f;
cnt++;
for (int i = 1; i <= 20; i++)
{
if (fa[x][i - 1] == -1)
fa[x][i] = -1;
else
fa[x][i] = fa[fa[x][i - 1]][i - 1];
}
for (auto [y, w] : e[x])
{
if (!ok[y])
continue;
if (dep[y] != -1)
{
edges.push_back({x, y, w});
continue;
}
dep[y] = dep[x] + 1;
val[y] = val[x] + w;
dfs(y, x);
}
};
function<int(int x, int y)> getfa = [&](int x, int y)
{
if (dep[x] < dep[y])
swap(x, y);
for (int i = 20; ~i; i--)
if (fa[x][i] != -1 && dep[fa[x][i]] >= dep[y])
x = fa[x][i];
if (x == y)
return x;
for (int i = 20; ~i; i--)
if (fa[x][i] != fa[y][i])
x = fa[x][i], y = fa[y][i];
return fa[x][0];
};
dfs(rt, -1);
for (auto [x, y, w] : edges)
{
int f = getfa(x, y);
i64 v = val[x] + val[y] - 2 * val[f];
if (v + w != 0)
{
q.push(x);
}
}
if (cnt != p[i].size())
assert(0);
}
ok.assign(n, 0);
while (!q.empty())
{
int x = q.front();
q.pop();
if (ok[x] != 0)
continue;
ok[x] = 1;
for (auto [y, w] : g[x])
{
if (ok[y])
continue;
ok[y] = 1;
q.push(y);
}
}
}
for (int i = 0; i < q; i++)
{
int x;
cin >> x;
x = (x % n + n) % n;
if (ok[x])
cout << "Yes\n";
else
cout << "No\n";
}
}
signed main()
{
std::ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int T = 1;
while (T--)
solve();
}
/*
3 2 3
1 1
-1 0
1
2
3
*/
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3572kb
input:
3 2 3 1 1 -1 3 1 2 3
output:
Yes Yes No
result:
ok 3 tokens
Test #2:
score: 0
Accepted
time: 0ms
memory: 3876kb
input:
3 2 3 1 1 -1 0 1 2 3
output:
No No No
result:
ok 3 tokens
Test #3:
score: 0
Accepted
time: 0ms
memory: 3568kb
input:
1 1 1 0 1000000000 -1000000000
output:
Yes
result:
ok "Yes"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3804kb
input:
3 2 3 0 1000000000 1 -1000000000 -1000000000 0 -1000000000
output:
No No No
result:
ok 3 tokens
Test #5:
score: -100
Wrong Answer
time: 327ms
memory: 63820kb
input:
50134 500000 500000 -154428638 -283522863 -186373509 -327130969 154999046 46750274 -933523447 349415487 -437683609 140099255 864996699 -262318199 811293034 -264299324 120273173 52410685 874944410 -52048424 445049930 -803690605 -138111276 -104634331 720288580 126597671 471164416 -348777147 -356502322...
output:
Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes Yes ...
result:
wrong answer 1st words differ - expected: 'No', found: 'Yes'