提出 #45641336


ソースコード 拡げる

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

typedef long long ll;

vector<vector<vector<ll>>> read_input(ll n, ll m) {
	vector<vector<vector<ll>>> v(n);
	for (ll i = 0; i < m; i++) {
		ll a, b, x, y;
		cin >> a >> b >> x >> y;
		a--; b--;
		v[a].push_back({b, x, y});
		v[b].push_back({a, -x, -y});
	}
	return v;
}

void solve () {
	vector<ll> ans;
	ll n, m;
	cin >> n >> m;
	vector<vector<vector<ll>>> v = read_input(n, m);
	vector<vector<ll>> pos(n);
	pos[0].push_back(0);
	pos[0].push_back(0);

	queue<ll> q;
	q.push(0);
	// for (ll i = 0; i < n; i++) {
	while (!q.empty()) {
		ll i = q.front();
		q.pop();
		ll len = v[i].size();
		for (ll j = 0; j < len; j++) {
			ll b = v[i][j][0];
			ll x = v[i][j][1];
			ll y = v[i][j][2];
			if (pos[b].size() < 2) {
				// pos[b] = {pos[i][0] + x, pos[i][1] + y};
				pos[b].push_back(pos[i][0] + x);
				pos[b].push_back(pos[i][1] + y);
				q.push(b);
			} else if (pos[b].size() == 2) {
				if ((pos[b][0] != pos[i][0] + x) || (pos[b][1] != pos[i][1] + y)) {
					pos[b].push_back(0);
				}
			}


		}
	}
	
	for (auto p: pos) {
		if (p.size() == 2) {
			cout << p[0] << " " << p[1] << endl;
		} else {
			cout << "undecidable" << endl;
		}
	}
	
}

int main (void) 
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
	solve();
	
	return 0;
}

/* Lorenzo Fiorini */

提出情報

提出日時
問題 D - Relative Position
ユーザ LorenFiorini
言語 C++ 17 (gcc 12.2)
得点 400
コード長 1388 Byte
結果 AC
実行時間 466 ms
メモリ 47708 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 400 / 400
結果
AC × 3
AC × 15
セット名 テストケース
Sample sample_01.txt, sample_02.txt, sample_03.txt
All random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, sample_01.txt, sample_02.txt, sample_03.txt
ケース名 結果 実行時間 メモリ
random_01.txt AC 448 ms 45776 KiB
random_02.txt AC 222 ms 33176 KiB
random_03.txt AC 444 ms 45880 KiB
random_04.txt AC 248 ms 26800 KiB
random_05.txt AC 417 ms 44180 KiB
random_06.txt AC 409 ms 42796 KiB
random_07.txt AC 266 ms 26484 KiB
random_08.txt AC 312 ms 31284 KiB
random_09.txt AC 409 ms 47708 KiB
random_10.txt AC 466 ms 47348 KiB
random_11.txt AC 2 ms 3528 KiB
random_12.txt AC 143 ms 29136 KiB
sample_01.txt AC 1 ms 3536 KiB
sample_02.txt AC 1 ms 3472 KiB
sample_03.txt AC 1 ms 3392 KiB