QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#159015#7107. Chaleurucup-team1134#AC ✓127ms6200kbC++173.1kb2023-09-02 17:20:182023-09-02 17:20:19

Judging History

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

  • [2023-09-02 17:20:19]
  • 评测
  • 测评结果:AC
  • 用时:127ms
  • 内存:6200kb
  • [2023-09-02 17:20:18]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=998244353,MAX=300005,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int Q;cin>>Q;
    while(Q--){
        int N,M;cin>>N>>M;
        vector<pair<int,int>> E(M);
        vector<int> deg(N);
        for(int i=0;i<M;i++){
            int a,b;cin>>a>>b;a--;b--;
            E[i]=mp(a,b);
            deg[a]++;
            deg[b]++;
        }
        vector<int> id(N);iota(all(id),0);
        sort(all(id),[&](int a,int b){
            return deg[a]>deg[b];
        });
        
        vector<int> pos(N);
        for(int i=0;i<N;i++) pos[id[i]]=i;
        
        for(int i=0;i<M;i++){
            auto [a,b]=E[i];
            a=pos[a];
            b=pos[b];
            if(a>b) swap(a,b);
            E[i]=mp(a,b);
        }
        
        {
            vector<int> CN(N);
            for(auto [a,b]:E){
                CN[b]++;
            }
            int L=0;
            for(int i=0;i<N;i++){
                if(CN[i]==i) L++;
                else break;
            }
            int ma=L;
            ll ans=1;
            
            vector<int> valid(N);
            for(auto [a,b]:E){
                if(b>=L&&a<L) valid[b]++;
            }
            
            for(int i=L;i<N;i++){
                if(valid[i]==L){
                    if(ma==L+1) ans++;
                    else{
                        ma=L+1;
                        ans=1;
                    }
                }else if(valid[i]==L-1){
                    if(ma==L) ans++;
                }
            }
            
            cout<<ans<<" ";
        }
        
        for(int i=0;i<M;i++){
            auto [a,b]=E[i];
            a=N-1-a;
            b=N-1-b;
            if(a>b) swap(a,b);
            E[i]=mp(a,b);
        }
        
        {
            vector<int> CN(N);iota(all(CN),0);
            for(auto [a,b]:E){
                CN[b]--;
            }
            int L=0;
            for(int i=0;i<N;i++){
                if(CN[i]==i) L++;
                else break;
            }
            int ma=L;
            ll ans=1;
            
            vector<int> valid(N,L);
            for(auto [a,b]:E){
                if(b>=L&&a<L) valid[b]--;
            }
            
            for(int i=L;i<N;i++){
                if(valid[i]==L){
                    if(ma==L+1) ans++;
                    else{
                        ma=L+1;
                        ans=1;
                    }
                }else if(valid[i]==L-1){
                    if(ma==L) ans++;
                }
            }
            
            cout<<ans<<"\n";
        }
    }
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
3 2
1 2
2 3
6 6
1 2
2 3
1 3
1 4
2 5
3 6
4 1
1 2

output:

2 1
1 4
1 2

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 127ms
memory: 6200kb

input:

2231
1 0
5 7
4 1
3 4
3 1
3 5
4 2
3 2
4 5
5 4
2 1
2 5
2 4
2 3
5 10
3 2
2 5
1 4
4 2
4 5
1 2
1 3
3 5
3 4
1 5
5 10
1 3
2 4
1 4
5 2
2 3
1 5
5 4
1 2
3 4
5 3
5 9
2 5
3 5
2 3
2 1
4 3
3 1
4 1
4 5
2 4
5 4
4 2
4 1
4 5
4 3
5 9
4 1
4 5
3 4
2 4
2 1
3 1
2 5
3 5
3 2
5 4
2 5
2 3
2 1
2 4
5 9
5 2
1 3
4 3
1 2
5 4
4 2
5...

output:

1 1
3 1
4 1
1 5
1 5
2 1
4 1
2 1
4 1
2 1
2 1
3 1
4 1
4 1
1 5
2 1
4 1
1 5
1 5
1 5
3 1
4 1
4 1
4 1
3 1
3 1
4 1
4 1
2 1
4 1
4 1
1 5
1 5
2 1
4 1
4 1
4 1
3 1
2 1
4 1
2 1
4 1
4 1
4 1
3 1
1 5
4 1
4 1
1 5
2 1
4 1
2 1
2 1
1 5
4 1
1 5
3 1
4 1
1 5
2 1
1 5
3 1
3 1
1 5
3 1
3 1
2 1
1 5
4 1
3 1
1 5
2 1
3 1
2 1
2 1
...

result:

ok 2231 lines

Extra Test:

score: 0
Extra Test Passed