QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#549837#7738. Equivalent RewritingHe2717970784WA 1ms6352kbC++171.5kb2024-09-06 21:56:212024-09-06 21:56:21

Judging History

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

  • [2024-09-06 21:56:21]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:6352kb
  • [2024-09-06 21:56:21]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 9;
int vis[N];
vector<int>edge[N];
vector<int>root;

void dfs(int u,bool flag){
    if(flag){
        cout << u << ' ';
    }
    for(int v : edge[u]){
        if(!vis[v]){
            vis[v] = 1;
            dfs(v,flag);
        }
    }
}

void solve(){
    int n = 0,m = 0;
    cin >> n >> m;
    root.clear();
    for(int i = 1;i <= m;i++){
        vis[i] = 0;
    }
    for(int i = 1;i <= n;i++){
        edge[i].clear();
    }
    for(int i = 1;i <= n;i++){
        int num = 0;
        cin >> num;
        while(num--){
            int x = 0;
            cin >> x;
            if(vis[x]){
                edge[vis[x]].push_back(i);
            }
            vis[x] = i;
        }
    }
    for(int i = 1;i <= n;i++){
        vis[i] = 0;
    }
    for(int i = 1;i <= n;i++){
        if(!vis[i]){
            root.push_back(i);
            vis[i] = 1;
            dfs(i,false);
        }
    }
    if((int)root.size() == 1){
        cout << "No" << endl;
        return;
    }
    reverse(root.begin(),root.end());
    for(int i = 1;i <= n;i++){
        vis[i] = 0;
    }
    cout << "Yes" << endl;
    for(int x : root){
        if(!vis[x]){
            vis[x] = 1;
            dfs(x,true);
        }
    }
    cout << endl;
}

signed main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int t = 0;
    cin >> t;
    while(t--){
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 5916kb

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: 6352kb

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)