QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#640620#7738. Equivalent RewritingDoubeecatWA 1ms3620kbC++201.7kb2024-10-14 14:48:482024-10-14 14:48:48

Judging History

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

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

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) cout << 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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3620kb

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
3 1 2 
No
No

result:

ok OK. (3 test cases)

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 3588kb

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)