QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#705060#6765. Don't Really Like How The Story EndsbeamishboysWA 213ms3584kbC++23974b2024-11-02 22:00:542024-11-02 22:01:00

Judging History

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

  • [2024-11-02 22:01:00]
  • 评测
  • 测评结果:WA
  • 用时:213ms
  • 内存:3584kb
  • [2024-11-02 22:00:54]
  • 提交

answer

#include <iostream>
#include <vector>
#include <set>
using namespace std;
using vi = vector<int>;

vector<vector<int>> sortAdj(vector<vector<int>> &adj) {
	vector<vector<int>> out(adj.size());
	for (int i = 0; i < adj.size(); i++) {
		for (int j : adj[i]) {
			out[j].push_back(i);
		}
	}
	return out;
}

void solve() {
	int n, m; cin >> n >> m;
	vector<vector<int>> adj(n+1);
	for (int i = 0; i < m; i++) {
		int u, v; cin >> u >> v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	adj = sortAdj(adj);
	vi st;

	st.push_back(1);
	int out = 0;
	while (st.size()) {
		int top = st.back();
		st.pop_back();
		if (top == n) break;
		for (int i : adj[top]) {
			if (i > top) {
				st.push_back(i);
			}
		}
		while (st.size() && st.back() <= top) st.pop_back();
		if (st.size() && st.back() == top+1) continue;
		out++;
		st.push_back(top+1);
	}
	cout << out << endl;
}

int main() {
	int t; cin >> t;
	while (t--) solve();
}

詳細信息

Test #1:

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

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: 213ms
memory: 3584kb

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:

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

result:

wrong answer 1st lines differ - expected: '0', found: '1'