QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#443576#6765. Don't Really Like How The Story Endsship2077RE 2ms8492kbC++17835b2024-06-15 15:59:422024-06-15 15:59:42

Judging History

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

  • [2024-06-15 15:59:42]
  • 评测
  • 测评结果:RE
  • 用时:2ms
  • 内存:8492kb
  • [2024-06-15 15:59:42]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
constexpr int M=1e5+5;
int n,m,x,y,tp,ans,stk[M];
vector<int>g[M],adj[M];
int read(){
	int x=0;char ch=getchar();
	while (!isdigit(ch)) ch=getchar();
	while (isdigit(ch)) x=x*10+ch-48,ch=getchar();
	return x;
}
void insert(int x){
	for (auto y:adj[x])
		g[y].emplace_back(x);
	stk[++tp]=x;
}
void erase(int x){
	while (stk[tp]!=x){
		for (auto y:adj[x])
			g[y].pop_back();
		tp--;
	}
}
void solve(){
	n=read();m=read();
	for (int i=1;i<=n;i++) g[i].clear(),adj[i].clear();
	for (int i=1;i<=m;i++){
		x=read();y=read();
		if (x>y) swap(x,y);
		adj[x].emplace_back(y);
	} tp=ans=0;insert(1);
	for (int i=2;i<=n;insert(i++))
		if (g[i].empty()) ans++;
		else erase(g[i].back());
	printf("%d\n",ans);
}
int main(){int T=read();while (T--) solve();return 0;}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 8492kb

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
Runtime Error

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:


result: