QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#406270#7107. ChaleurSortingAC ✓151ms17268kbC++202.1kb2024-05-07 04:36:412024-05-07 04:36:42

Judging History

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

  • [2024-05-07 04:36:42]
  • 评测
  • 测评结果:AC
  • 用时:151ms
  • 内存:17268kb
  • [2024-05-07 04:36:41]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
typedef unsigned long long ull ;
typedef pair < int , int > pii ;
typedef vector < int > vi ;
#define fi first
#define se second
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()

const int MAXN = 1e5 + 7 ;

int n , m ;
vector < int > v[ MAXN ] ;
int deg[ MAXN ] ;
pii srt[ MAXN ] ;
int wh[ MAXN ] ;

void solve ( ) {
    cin >> n >> m ;
    for ( int i = 1 ; i <= n ; ++ i ) {
        v[ i ].clear ( ) , deg[ i ] = 0 ;
    }
    for ( int i = 1 , x , y ; i <= m ; ++ i ) {
        cin >> x >> y ;
        v[ x ].push_back ( y ) ;
        v[ y ].push_back ( x ) ;
        ++ deg[ x ] , ++ deg[ y ] ;
    }
    for ( int i = 1 ; i <= n ; ++ i ) {
        srt[ i ] = { deg[ i ] , i } ;
    }
    sort ( srt + 1 , srt + n + 1 , greater < pii > ( ) ) ;
    for ( int i = 1 ; i <= n ; ++ i ) {
        wh[ srt[ i ].se ] = i ;
    }
    int mx = 1 ;
    bool done = false ;
    int mxsz = 0 ;
    for ( int ctr = 1 ; ctr <= n ; ++ ctr ) {
        int i = srt[ ctr ].se ;
        int cnt = 0 ;
        for ( auto j : v[ i ] ) {
            if ( wh[ j ] < wh[ i ] ) { ++ cnt ; }
        }
        if ( cnt == ctr - 1 ) { ++ mxsz ; continue ; }
        if ( cnt == mxsz - 1 ) { ++ mx ; }
    }
    int mn = n - mxsz , mn_cnt = 1 ;
    for ( int ctr = 1 ; ctr <= mxsz ; ++ ctr ) {
        int i = srt[ ctr ].se ;
        int cnt = 0 ;
        for ( auto j : v[ i ] ) {
            if ( mxsz < wh[ j ] ) { ++ cnt ; }
        }
        if ( cnt == 0 ) {
            if ( mn < n - mxsz + 1 ) {
                mn = n - mxsz + 1 ;
                mn_cnt = 0 ;
            }
            ++ mn_cnt ;
        }
        if ( cnt == 1 ) {
            if ( mn == n - mxsz ) { ++ mn_cnt ; }
        }
    }
    cout << mx << " " << mn_cnt << "\n" ;
}

int main ( ) {
    ios_base :: sync_with_stdio ( false ) ;
    cin.tie ( NULL ) ;
    int t = 1 ; cin >> t ;
    while ( t -- ) { solve ( ) ; }
    return 0 ;
}

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

详细

Test #1:

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

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: 151ms
memory: 17268kb

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