QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#138359#6526. Canvasneko_nyaa#WA 1ms3540kbC++232.5kb2023-08-11 16:26:232023-08-11 16:26:25

Judging History

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

  • [2023-08-11 16:26:25]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3540kb
  • [2023-08-11 16:26:23]
  • 提交

answer

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

#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()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

vi val, comp, z, cont;
int Time, ncomps;
template<class G, class F> int dfs(int j, G& g, F& f) {
	int low = val[j] = ++Time, x; z.push_back(j);
	for (auto e : g[j]) if (comp[e] < 0)
		low = min(low, val[e] ?: dfs(e,g,f));

	if (low == val[j]) {
		do {
			x = z.back(); z.pop_back();
			comp[x] = ncomps;
			cont.push_back(x);
		} while (x != j);
		f(cont); cont.clear();
		ncomps++;
	}
	return val[j] = low;
}
template<class G, class F> void scc(G& g, F f) {
	int n = sz(g);
	val.assign(n, 0); comp.assign(n, -1);
	Time = ncomps = 0;
	rep(i,0,n) if (comp[i] < 0) dfs(i, g, f);
}

void dfs(int now, vector<int> &vis, vector<int> &visord, vector<vector<pair<int, int>>> &adj) {
	vis[now] = 1;
	for (auto [u, id]: adj[now]) {
		visord.push_back(id);
		if (!vis[u]) dfs(u, vis, visord, adj);
	}
}

void solve() {
	int n, m; cin >> n >> m;
	vector<int> scr(n+1);
	vector<int> bade, goode;
	vector<tuple<int, int, int, int>> ops;
	for (int i = 0; i < m; i++) {
		int u, x, v, y; cin >> u >> x >> v >> y;
		u--, v--;
		ops.emplace_back(u, x, v, y);
		if (x == 1 && y == 1) {
			bade.push_back(i);
		} else if (x == 2 && y == 2) {
			goode.push_back(i);
			scr[u] = scr[v] = 1;
		}
	}

	vector<vector<int>> g(n);
	vector<vector<pair<int, int>>> adj(n);
	int ptr = 0;
	for (auto [u, x, v, y]: ops) {
		if (x == 1 && y == 2) {
			g[u].push_back(v);
			adj[u].emplace_back(v, ptr);
		} else if (x == 2 && y == 1) {
			g[v].push_back(u);
			adj[v].emplace_back(u, ptr);
		}
		ptr++;
	}

	vector<int> tps;
	scc(g, [&](vi& v) {
		for (int i: v) tps.push_back(i);
	});

	reverse(tps.begin(), tps.end());
	vector<int> visord;
	vector<int> vis(n);
	for (int i: tps) {
		if (!vis[i]) {
			dfs(i, vis, visord, adj);
		}
	}

	reverse(visord.begin(), visord.end());

	// answer
	vector<int> ans;
	for (int i: bade) ans.push_back(i);
	for (int i: visord) ans.push_back(i);
	for (int i: goode) ans.push_back(i);

	vector<int> fl(n);
	for (int i: ans) {
		auto [u, x, v, y] = ops[i];
		fl[u] = x; fl[v] = y;
	}

	cout << accumulate(fl.begin(), fl.end(), 0LL) << '\n';
	for (int i: ans) cout << i+1 << ' ';
		cout << '\n';
}

signed main() {
	ios::sync_with_stdio(0); cin.tie(0);

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

	return 0;
}

詳細信息

Test #1:

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

input:

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

output:

7
4 1 2 3 
5
2 1 

result:

ok Correct. (2 test cases)

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 3540kb

input:

1
10 13
1 1 2 2
2 1 3 2
1 2 3 1
3 1 4 2
4 1 5 2
5 1 6 2
4 2 6 1
7 1 8 2
8 1 9 2
7 2 9 1
5 2 9 1
8 2 10 2
1 1 10 1

output:

18
13 4 3 2 1 5 7 6 11 10 9 8 12 

result:

wrong answer Jury has better answer. Participant 18, jury 19 (test case 1)