QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#322322#6765. Don't Really Like How The Story EndsYarema#WA 61ms6048kbC++141.2kb2024-02-06 20:34:402024-02-06 20:34:41

Judging History

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

  • [2024-02-06 20:34:41]
  • 评测
  • 测评结果:WA
  • 用时:61ms
  • 内存:6048kb
  • [2024-02-06 20:34:40]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;

const int N = 100'447;
VI g[N];
bool used[N];
int ans;
int mx = 0;

void dfs(int v)
{
	used[v] = 1;
	mx = max(mx, v);
	for (auto to : g[v])
	{
		if (used[to])
			continue;
		if (to != mx + 1 && !used[mx + 1])
		{
			ans++;
			dfs(mx + 1);
		}
		if (used[to])
			continue;
		dfs(to);
	}
}

void solve()
{
	int n, m;
	cin >> n >> m;
	FOR (i, 0, m)
	{
		int u, v;
		cin >> u >> v;
		u--, v--;
		g[u].PB(v);
		g[v].PB(u);
	}
	FOR (i, 0, n)
		sort(ALL(g[i]));
	ans = 0;
	dfs(0);
	FOR (i, 1, n)
	{
		if (!used[i])
		{
			ans++;
			dfs(i);
		}
	}
	cout << ans << '\n';
	mx = 0;
	FOR (i, 0, n)
	{
		g[i].clear();
		used[i] = 0;
	}
}

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



Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
2 3
1 1
1 2
2 1
4 1
1 4
4 2
1 2
3 4

output:

0
2
1

result:

ok 3 lines

Test #2:

score: -100
Wrong Answer
time: 61ms
memory: 6048kb

input:

117747
3 7
2 1
3 3
1 3
1 1
3 2
1 1
3 1
4 8
2 3
4 3
3 2
4 2
1 3
2 1
4 3
2 4
3 4
2 3
2 2
3 3
1 1
2 5
1 1
2 2
2 2
1 2
2 2
3 7
2 1
1 2
3 3
3 2
1 2
3 3
3 2
4 5
1 2
3 3
4 4
1 4
2 1
3 1
3 2
1 3
1 1
1 1
1 1
1 6
1 1
1 1
1 1
1 1
1 1
1 1
5 4
2 1
2 5
1 3
3 2
4 7
1 1
2 4
3 2
1 1
1 1
4 2
2 3
5 8
3 3
2 2
4 2
1 4
1...

output:

0
0
1
0
0
1
1
0
0
1
1
1
0
0
2
0
2
0
1
0
0
3
0
0
0
2
1
1
1
0
0
0
2
0
2
1
3
0
2
0
3
1
2
1
0
0
1
2
0
2
0
1
2
0
0
2
0
0
0
1
0
3
0
1
0
0
1
0
0
2
2
0
0
0
1
0
2
3
0
1
1
1
1
0
0
2
1
2
0
1
2
0
0
0
3
0
0
3
1
0
2
0
0
0
1
0
0
0
0
0
0
4
0
0
0
0
0
0
2
0
1
0
0
1
1
0
0
2
0
1
0
0
0
2
0
1
2
1
0
0
0
1
0
0
1
1
1
0
0
0
...

result:

wrong answer 70th lines differ - expected: '3', found: '2'