QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#470298 | #5504. Flower Garden | lhzawa | WA | 0ms | 56304kb | C++14 | 3.6kb | 2024-07-10 11:52:04 | 2024-07-10 11:52:05 |
Judging History
answer
// Powered by CP Editor (https://cpeditor.org)
#include<bits/stdc++.h>
const int maxn = 1e5 + 10, maxq = 1e5 + 10, maxN = maxn * 3 + maxq * 2;
int n, m, N;
std::vector<int> to[maxN];
inline int newnode() {to[++N].clear(); return N;}
inline void add(int x, int y) {to[x].push_back(y);}
int id[maxn * 4][2];
void build(int k = 1, int l = 1, int r = n) {
if (l == r) {
for (int w : {0, 1})
id[k][w] = l;
return ;
}
int mid = (l + r) >> 1;
build(k << 1, l, mid), build(k << 1 | 1, mid + 1, r);
for (int w : {0, 1}) {
id[k][w] = newnode();
if (! w) add(id[k << 1][w], id[k][w]), add(id[k << 1 | 1][w], id[k][w]);
else add(id[k][w], id[k << 1][w]), add(id[k][w], id[k << 1 | 1][w]);
}
}
void add(int x, int y, int w, int u, int k = 1, int l = 1, int r = n) {
if (x <= l && r <= y)
return ! w ? add(id[k][w], u) : add(u, id[k][w]), void();
int mid = (l + r) >> 1;
if (x <= mid) add(x, y, w, u, k << 1, l, mid);
if (mid < y) add(x, y, w, u, k << 1 | 1, mid + 1, r);
}
int dfn[maxN], low[maxN], stk[maxN], top, ins[maxN], dN;
int bl[maxN], siz[maxN], bN;
std::vector<int> son[maxN], G[maxN];
void dfs(int u) {
dfn[u] = low[u] = ++dN, stk[++top] = u, ins[u] = 1;
for (int v : to[u]) {
if (! dfn[v])
dfs(v), low[u] = std::min(low[u], low[v]);
else if (ins[v])
low[u] = std::min(low[u], dfn[v]);
}
if (low[u] < dfn[u])
return ;
bN++, son[bN].clear(), G[bN].clear();
do {
bl[stk[top]] = bN, son[bN].push_back(stk[top]), ins[stk[top]] = 0;
} while (stk[top--] != u);
}
int deg[maxN], ord[maxN];
char S[maxn];
int col[maxN];
void dfsc(int u) {
if (col[u]++) return ;
for (int v : G[u])
dfsc(v);
}
inline void Main() {
scanf("%d%d", &n, &m), n *= 3;
int lim = n / 3;
N = 0;
for (int i = 1; i <= n; i++) newnode();
build();
for (int a, b, c, d; m--; ) {
scanf("%d%d%d%d", &a, &b, &c, &d);
int x = newnode(), y = newnode();
add(a, b, 0, x), add(c, d, 1, y);
add(x, y);
}
memset(dfn, 0, sizeof(int) * (N + 1));
dN = bN = 0;
for (int i = 1; i <= N; i++)
if (! dfn[i])
dfs(i);
memset(siz, 0, sizeof(int) * (bN + 1));
for (int i = 1; i <= n; i++)
siz[bl[i]]++;
memset(deg, 0, sizeof(int) * (bN + 1));
for (int i = 1; i <= N; i++)
for (int j : to[i])
if (bl[i] != bl[j])
G[bl[i]].push_back(bl[j]), deg[bl[j]]++;
std::priority_queue<std::pair<int, int> > Q;
for (int i = 1; i <= bN; i++)
if (! deg[i])
Q.emplace(siz[i], i);
for (int i = 1; i <= bN; i++) {
int u = Q.top().second; Q.pop();
ord[i] = u;
for (int v : G[u])
if (! -- deg[v])
Q.emplace(siz[v], v);
}
for (int i = bN, tot = 0; ; i--) {
tot += siz[ord[i]];
if (lim <= tot && tot <= lim * 2) {
puts("TAK");
for (int u = 1; u <= n; u++)
printf("%c", "FR"[ord[bl[u]] >= i]);
puts("");
return ;
} else if (tot > lim * 2)
break;
}
for (int i = 1; i <= bN; i++) if (siz[i] >= lim) {
memset(col, 0, sizeof(int) * (bN + 1));
dfsc(i);
int cnt = 0;
for (int j = 1; j <= bN; j++)
cnt += (col[j] > 0) * siz[j];
if (lim <= cnt && cnt <= lim * 2) {
puts("TAK");
for (int u = 1; u <= n; u++)
printf("%c", "FR"[col[bl[u]] > 0]);
puts("");
return ;
}
}
puts("NIE");
}
int main() {
int z; scanf("%d", &z);
while (z--) Main();
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 56304kb
input:
2 1 3 1 1 2 2 1 2 3 3 1 1 3 3 1 3 1 1 2 2 2 2 3 3 3 3 1 1
output:
TAK FFR NIE
result:
wrong answer odpowiedz nie spelnia wymogow!