QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#135796#501. SubwayMohammed_Atalah#0 4ms11452kbC++173.1kb2023-08-06 01:41:582024-07-04 01:18:05

Judging History

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

  • [2024-07-04 01:18:05]
  • 评测
  • 测评结果:0
  • 用时:4ms
  • 内存:11452kb
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-06 01:41:58]
  • 提交

answer

/// Template path: /home/mohammed/.config/sublime-text-3/Packages/User

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;

// typedef
typedef long long ll;
typedef long double ld;
typedef vector<int> vecint;
typedef vector<char> vecchar;
typedef vector<string> vecstr;
typedef vector<long long> vecll;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

// Marcos
#define endl ("\n")
#define int long long
#define mod 1000000007
#define pi (3.141592653589)
#define REP(i,a,b) for (int i = a; i < b; i++)
#define RREP(i,a,b) for (int i = a; i > b; i--)
#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)

// Functions
long long squared(long long x) {return (x * x) % mod;}
int factorial(int n) {long long res = 1; for (int i = 1; i <= n; i++) {res = ((res * i) % mod + mod) % mod ;} return res;}
long long power(long long x, long long p) {if (p == 0) {return 1;} if (p % 2 == 1) {return (power(x, p - 1) * x) % mod;} return squared(power(x, p / 2));}

// cout << fixed;
// cout << setprecision(4);


// ---------(^_^)--------- //


vector<vector<int>> check_new(1000, vector<int>(1000, 0));
vector<vector<int>> edg;

vector<int> vis;
bool e = 0;
vector<vector<int>> to_del;
vector<vector<int>> result1;
vector<vector<int>> result2;
void dfs(int idx, int parent) {
	if (e) return;
	for (auto &i : edg[idx]) {
		if (vis[i] && i != parent && check_new[i][idx] != -2 && !e) {
			e = 1;
			check_new[to_del[0][0]][to_del[0][1]] = -2;
			check_new[to_del[0][1]][to_del[0][0]] = -2;
			result1.push_back({to_del[0][0], to_del[0][1]});
			return;
		} else if (vis[i] || check_new[i][idx] == -2 ) {
			continue;
		} else {
			vis[i] = 1;
			if (check_new[idx][i] == -1) {
				to_del.push_back({idx, i});
			}
			dfs(i, idx);
			if (check_new[idx][i] == -1 && !e) {
				to_del.pop_back();
			}
			vis[i]--;
		}
	}


}

void main_solve() {


	int n; cin >> n;

	edg.resize(n);
	vis.resize(n);
	for (int i = 0; i < n - 1; i ++) {
		int a, b; cin >> a >> b;
		check_new[a][b] = -1;
		check_new[b][a] = -1;
		edg[a].push_back(b);
		edg[b].push_back(a);
	}

	for (int i = 0; i < n - 1; i ++) {
		int a, b; cin >> a >> b;
		if (check_new[a][b] == -1) {
			check_new[a][b] = 1;
			check_new[b][a] = 1;
			continue;
		}
		e = 0;
		vis.clear();
		to_del.clear();
		vis.resize(n);
		check_new[a][b] = 1;
		check_new[b][a] = 1;
		edg[a].push_back(b);
		edg[b].push_back(a);
		vis[a] = 1;
		dfs(a, a);
		result2.push_back({a, b});
	}

	int  o = result1.size();
	cout << o << endl;
	for (int i  = 0; i < o ; i++) {
		cout << result1[i][0] << " ";
		cout << result1[i][1] << " ";
		cout << result2[i][0] << " ";
		cout << result2[i][1] << " ";
		cout << endl;
	}


}


int32_t main() {

	fast;
// #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
// #endif
	// Just another problem (-_-)

	int t;
	t = 1;
	// cin >> t;

	while (t--) {
		main_solve();
	}


}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 4ms
memory: 11452kb

input:

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

output:

7
8 2 8 9 
1 8 1 2 
6 0 6 1 
8 7 9 4 
7 4 7 1 
2 5 4 7 
2 0 1 0 

result:

wrong answer Uses more moves than judge

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #1:

0%