QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#792991#7738. Equivalent Rewritingeinekleine18WA 0ms3632kbC++201.6kb2024-11-29 15:35:262024-11-29 15:35:26

Judging History

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

  • [2024-11-29 15:35:26]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3632kb
  • [2024-11-29 15:35:26]
  • 提交

answer

#include <algorithm>
#include<bits/stdc++.h>
#include <functional>
#include <queue>
#include <vector>

#define int long long
using namespace std;
#define endl '\n'
using a2=std::array<int,2>;

void solve(){
    int n,m;
    std::cin>>n>>m;
    std::vector<int>last(m,-1);
    std::vector<int>dep(n);
    for(int i=0;i<n;++i){
        int p;
        std::cin>>p;
        for(int j=0;j<p;++j){
            int x;
            std::cin>>x;
            --x;
            if(last[x]!=-1){
                dep[i]=std::max(dep[i],dep[last[x]]+1);
            }
            last[x]=i;
        }
    }
    std::vector ng(n,std::vector<int>());
    for(int i=0;i<n;++i){
        ng[dep[i]].push_back(i);
    }
    std::vector<int>ans;
    int f=0;
    for(int i=0;i<n;++i){
        if((int)ng[i].size()>1){
            f=1;
            std::sort(ng[i].begin(),ng[i].end(),std::greater<int>());
        }
        for(auto &x:ng[i]){
            ans.push_back(x);
        }
    }
    if(f){
        std::cout<<"Yes\n";
        int cnt=0;
        assert(ans.size()==n);
        for(auto &x:ans){
            std::cout<<x+1;
            ++cnt;
            if(cnt<n) std::cout<<' ';
        }
        std::cout<<'\n';
    }else{
        std::cout<<"No\n";
    }
}

signed main(){
#ifdef LOCAL 
    std::freopen("in.txt","r",stdin);
    std::freopen("out.txt","w",stdout);
#endif
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    int _=1;
    std::cin>>_;
    for(int i=0;i<_;++i){
        solve();
    }
}

详细

Test #1:

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

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: 0ms
memory: 3632kb

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)