QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#601913 | #7738. Equivalent Rewriting | MiniLong# | WA | 2ms | 9316kb | C++17 | 3.6kb | 2024-09-30 15:48:43 | 2024-09-30 15:48:44 |
Judging History
answer
#include <bits/stdc++.h>
#define _rep(i, x, y) for(int i = x; i <= y; ++i)
#define _req(i, x, y) for(int i = x; i >= y; --i)
#define _rev(i, u) for(int i = head[u]; i; i = e[i].nxt)
#define pb push_back
#define fi first
#define se second
#define mst(f, i) memset(f, i, sizeof f)
using namespace std;
#ifdef ONLINE_JUDGE
#define debug(...) 0
#else
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#endif
typedef long long ll;
typedef pair<int, int> PII;
namespace fastio{
#ifdef ONLINE_JUDGE
char ibuf[1 << 20],*p1 = ibuf, *p2 = ibuf;
#define get() p1 == p2 && (p2 = (p1 = ibuf) + fread(ibuf, 1, 1 << 20, stdin), p1 == p2) ? EOF : *p1++
#else
#define get() getchar()
#endif
template<typename T> inline void read(T &t){
T x = 0, f = 1;
char c = getchar();
while(!isdigit(c)){
if(c == '-') f = -f;
c = getchar();
}
while(isdigit(c)) x = x * 10 + c - '0', c = getchar();
t = x * f;
}
template<typename T, typename ... Args> inline void read(T &t, Args&... args){
read(t);
read(args...);
}
template<typename T> void write(T t){
if(t < 0) putchar('-'), t = -t;
if(t >= 10) write(t / 10);
putchar(t % 10 + '0');
}
template<typename T, typename ... Args> void write(T t, Args... args){
write(t), putchar(' '), write(args...);
}
template<typename T> void writeln(T t){
write(t);
puts("");
}
template<typename T> void writes(T t){
write(t), putchar(' ');
}
#undef get
};
using namespace fastio;
#define multitest() int T; read(T); _rep(tCase, 1, T)
namespace Calculation{
const ll mod = 998244353;
ll ksm(ll p, ll h){ll base = p % mod, res = 1; while(h){if(h & 1ll) res = res * base % mod; base = base * base % mod, h >>= 1ll;} return res;}
void dec(ll &x, ll y){x = ((x - y) % mod + mod) % mod;}
void add(ll &x, ll y){x = (x + y) % mod;}
void mul(ll &x, ll y){x = x * y % mod;}
ll sub(ll x, ll y){return ((x - y) % mod + mod) % mod;}
ll pls(ll x, ll y){return ((x + y) % mod + mod) % mod;}
ll mult(ll x, ll y){return x * y % mod;}
}
using namespace Calculation;
const int N = 1e5 + 5;
int n, m, in[N];
vector<int> p[N], G[N];
int main(){
multitest(){
read(n, m);
_rep(i, 1, n){
int k, x; read(k);
_rep(j, 1, k){
read(x), p[x].pb(i);
}
}
_rep(i, 1, m){
int len = p[i].size();
if(len > 1){
_rep(j, 0, len - 2) G[p[i][len - 1]].pb(p[i][j]), in[p[i][j]]++;
}
}
queue<int> q; vector<int> cur, ans; bool ok = 0;
_rep(i, 1, n) if(!in[i]) cur.pb(i);
if(cur.size() > 1){
sort(cur.begin(), cur.end());
ok = 1; for(auto &i : cur) q.push(i);
}
while(q.size()){
int u = q.front(); q.pop();
ans.pb(u);
cur.clear();
for(auto &v : G[u]){
if(!--in[v]) cur.pb(v);
}
if(!ok && cur.size() > 1){
sort(cur.begin(), cur.end()), ok = 1;
}
for(auto &i : cur) q.push(i);
}
if(!ok) puts("No");
else{
puts("Yes");
reverse(ans.begin(), ans.end());
for(auto &i : ans) writes(i); puts("");
}
_rep(i, 1, m) p[i].clear();
_rep(i, 1, n) in[i] = 0, G[i].clear();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 9316kb
input:
3 3 6 3 3 1 5 2 5 3 2 2 6 2 3 3 1 3 2 2 3 1 1 3 2 2 1
output:
Yes 1 3 2 No No
result:
ok OK. (3 test cases)
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 8248kb
input:
1 10 5 2 2 4 4 1 3 4 2 1 2 3 2 1 4 4 5 2 4 3 3 2 5 4 3 5 4 2 3 1 3 2 5 1 4 2 3 5 1 4
output:
No
result:
wrong answer jury found an answer but participant did not (test case 1)