QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#640618#7738. Equivalent RewritingDoubeecatWA 1ms3820kbC++201.7kb2024-10-14 14:48:182024-10-14 14:48:19

Judging History

你现在查看的是最新测评结果

  • [2024-10-14 14:48:19]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3820kb
  • [2024-10-14 14:48:18]
  • 提交

answer

/*
Undo the destiny.
*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair

const int N = 1e5 + 10;
vector <int> G[N];
int n,m,lst[N],deg[N];

void solve() {
    cin >> n >> m;
    for (int i = 1;i <= m;++i) lst[i] = 0;
    for (int i = 1;i <= n;++i) G[i].clear(),deg[i] = 0;
    int cnt;cin >> cnt;
    for (int i = 1;i <= cnt;++i) {
        int x;cin >> x;lst[x] = 1;
    }
    set <pii> edg;
    for (int i = 2;i <= n;++i) {
        cin >> cnt;
        for (int j = 1;j <= cnt;++j) {
            int x;cin >> x;
            if(lst[x]) edg.insert(mp(lst[x],i));
            lst[x] = i;
        }
    }
    for (auto [x,y] : edg) {
        G[x].push_back(y);++deg[y];
        //cout << "e:" << x << " " << y <<"\n";
    }
    int tot = 0;
    queue <int> q;
    for (int i = 2;i <= n;++i) {
        if (!deg[i] && i != 1) {
            ++tot;
            q.push(i);
        }
    }
    ++tot;q.push(1);
    if (tot > 1) {
        cout << "Yes\n";
        vector <int> ans;
        while (!q.empty()) {
            int x = q.front();q.pop();
            ans.push_back(x);
            for (auto y : G[x]) {
                if (!--deg[y]) {
                    q.push(y);
                }
            }
        }
        for(auto x : ans) printf("%d ",x);
        cout << "\n";
    } else {
        cout << "No\n";
    }
}

signed main() {
    ios::sync_with_stdio(false);
    //cin.tie(0);//cout.tie(0);
    int T;cin >> T;
    while (T--) solve();
    return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3820kb

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

No
No
3 1 2 

result:

wrong output format Expected integer, but "No" found (test case 1)