QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#189155 | #6705. Median | ZXG_DZXX | WA | 3ms | 3616kb | C++17 | 1.7kb | 2023-09-26 21:59:47 | 2023-09-26 21:59:48 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
typedef pair<int, int> PII;
typedef long long ll;
void solve()
{
int n, m;
cin >> n >> m;
vector<vector<int>> g(n + 1), rg = g;
vector<int> din(n + 1);
for(int i = 0; i < m; i++)
{
int u, v;
cin >> u >> v;
g[u].push_back(v);
rg[v].push_back(u);
din[v]++;
}
queue<int> q;
for(int i = 1; i <= n; i++) if(!din[i]) q.push(i);
queue<int> Q = q;
while(q.size())
{
auto u = q.front();
q.pop();
for(auto v : g[u]) if(!--din[v]) q.push(v);
}
if(*max_element(din.begin(), din.end()))
{
for(int i = 1; i <= n; i++) cout << 0;
cout << '\n';
return;
}
auto get = [&](vector<vector<int>> &g)
{
vector<int> d(n + 1);
for(int u = 1; u <= n; u++) for(auto v : g[u]) d[v]++;
vector<int> top;
queue<int> q;
for(int i = 1; i <= n; i++) if(!d[i]) q.push(i), top.push_back(i);
while(q.size())
{
auto u = q.front();
q.pop();
for(auto v : g[u]) if(!--d[v]) q.push(v), top.push_back(v);
}
vector<int> pre(n + 1);
for(auto u : top) for(auto v : g[u]) pre[v] += pre[u] + 1;
return pre;
};
auto pre = get(g), nxt = get(rg);
for(int i = 1; i <= n; i++)
if(pre[i] <= n / 2 && nxt[i] <= n / 2) cout << 1;
else cout << 0;
cout << '\n';
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int T; cin >> T; while(T--)
solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3512kb
input:
2 5 4 1 2 3 2 2 4 2 5 3 2 1 1 2 3
output:
01000 000
result:
ok 2 lines
Test #2:
score: -100
Wrong Answer
time: 3ms
memory: 3616kb
input:
66 13 2 9 13 7 11 11 19 9 1 8 1 5 1 2 8 4 2 2 1 5 2 6 3 3 11 3 2 4 6 6 10 9 8 3 5 1 7 5 8 3 9 4 9 6 7 3 1 2 3 11 6 9 4 1 6 5 2 1 5 4 6 8 4 15 15 10 6 15 8 7 6 11 1 5 2 3 4 11 13 4 6 10 12 10 13 1 6 15 2 5 12 13 14 5 3 15 86 14 12 8 1 14 9 8 15 5 10 1 9 11 2 6 2 7 10 10 13 14 5 4 13 5 8 4 10 13 9 6 9...
output:
1111111111111 00000000111 111 11111111111 111111111111111 000000000000000 00000 01000 1111111 0000000000000 111000101 111111111 000000001010000 010111111 000000000 0000000000000 1111111111111 000000000000000 00000101001 000000000000000 11111111111 00000000000 11111 00000000000 11101110111 00000 1111...
result:
wrong answer 2nd lines differ - expected: '01001000111', found: '00000000111'