QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#158418#7107. Chaleurucup-team1325#AC ✓796ms22356kbC++172.0kb2023-09-02 16:30:342023-09-02 16:30:37

Judging History

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

  • [2023-09-02 16:30:37]
  • 评测
  • 测评结果:AC
  • 用时:796ms
  • 内存:22356kb
  • [2023-09-02 16:30:34]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

typedef long long ll; typedef unsigned long long ull;
const int inf = 1e9; const ll llnf = 4e18;

template< class Tp > void chkmax( Tp &x , Tp y ) { x = max( x , y ); }
template< class Tp > void chkmin( Tp &x , Tp y ) { x = min( x , y ); }

void solve( ) {
	int n , m; cin >> n >> m;
	vector< set< int > > G( n + 1 ); vector< int > deg( n + 1 ); for( int i = 1; i <= m; i ++ ) { int u , v; cin >> u >> v; G[u].emplace( v ) , G[v].emplace( u ); deg[u] ++ , deg[v] ++; }

	vector< vector< int > > S( n + 1 ); for( int u = 1; u <= n; u ++ ) S[deg[u]].emplace_back( u );
	vector< int > P;
	for( int d = n; d >= 0; d -- ) {
		bool bad = false;
		for( int i = 0; i < ( int ) S[d].size( ) && !bad; i ++ ) {
			for( int j = 0; j < ( int ) P.size( ) && !bad; j ++ ) if( !G[S[d][i]].count( P[j] ) ) bad = true;
			for( int j = i + 1; j < ( int ) S[d].size( ) && !bad; j ++ ) if( !G[S[d][i]].count( S[d][j] ) ) bad = true;
		}
		if( !bad ) for( int u : S[d] ) P.emplace_back( u );
		else {
			for( int u : S[d] ) {
				bad = false;
				for( int j = 0; j < ( int ) P.size( ) && !bad; j ++ ) if( !G[u].count( P[j] ) ) bad = true;
				if( !bad ) P.emplace_back( u );
			}
			break;
		}
	}
	vector< bool > grp( n + 1 ); for( int u : P ) grp[u] = true;

	int ans1 = 1;
	for( int u = 1; u <= n; u ++ ) if( !grp[u] ) {
		int bad = 0;
		for( int j = 0; j < ( int ) P.size( ) && bad <= 1; j ++ ) if( !G[u].count( P[j] ) ) bad ++;
		if( bad <= 1 ) ans1 ++;
	}

	vector< int > c( n + 1 ); for( int v = 1; v <= n; v ++ ) if( !grp[v] ) c[v] = -1;
	for( int u = 1; u <= n; u ++ ) if( !grp[u] ) for( int v : G[u] ) if( grp[v] ) c[v] ++;
	int ans2 = ( count( c.begin( ) + 1 , c.begin( ) + n + 1 , 0 ) > 0 ) ? ( count( c.begin( ) + 1 , c.begin( ) + n + 1 , 0 ) ) : ( 1 + count( c.begin( ) + 1 , c.begin( ) + n + 1 , 1 ) );

	cout << ans1 << " " << ans2 << "\n";
}

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

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 796ms
memory: 22356kb

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