Submission #373742


Source Code Expand

#include <string>
#include <vector>
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <sstream>
#include <algorithm>
#include <cstring>

using namespace std;
typedef long long LL;

#define MAX 1000000000


int edgeId[1001][1001];
int cut[1001][1001];
int edgeA[1001];
int edgeB[1001];
int edgeC[1001];
vector<int> con[1001];

int visited[1001];
int min_edge_value;
int min_edge_id;

void min_search(int current) {
	vector<int> nexts = con[current];

	visited[current] = 1;
	for (int i = 0; i < nexts.size(); i++) {
		int next = nexts[i];
		if (visited[next]) continue;
		if (cut[current][next]) continue;

		int e = edgeId[current][next];
		int d = edgeC[e];
//		cerr << "edgeId: " << e << ", value: " << d << endl;
		if (min_edge_value > d) {
			min_edge_value = d;
			min_edge_id = e;
		} else if (min_edge_value == d) {
			if (min_edge_id > e) {
				min_edge_id = e;
			}
		}
		min_search(next);
	}
}

void query1() {
	int v, d; cin >> v >> d;
	int a = edgeA[v];
	int b = edgeB[v];

	if (cut[a][b]) return;

	edgeC[v] += d;
}
void query2() {
	int v; cin >> v;

	int a = edgeA[v];
	int b = edgeB[v];
	if (cut[a][b]) {
		cout << -1 << endl;
		return;
	}

	min_edge_value = MAX;
	memset(visited, 0, sizeof(visited));
	min_search(a);
	cout << min_edge_id << endl;

	int removeA = edgeA[min_edge_id];
	int removeB = edgeB[min_edge_id];

	cut[removeA][removeB] = 1;
	cut[removeB][removeA] = 1;	
}

int main() {
	int N; cin >> N;
	for (int i = 1; i <= N - 1; i++) {
		int a, b, c; cin >> a >> b >> c;
		con[a].push_back(b);
		con[b].push_back(a);
		edgeA[i] = a;
		edgeB[i] = b;
		edgeC[i] = c;
		edgeId[a][b] = i;
		edgeId[b][a] = i;
	}

	int Q; cin >> Q;
	for (int i = 0; i < Q; i++) {
		int type; cin >> type;
		if (type == 1) {
			query1();
		} else if (type == 2) {
			query2();
		}
	}

	return 0;
}

Submission Info

Submission Time
Task I - 盆栽
User greentea
Language C++ (GCC 4.9.2)
Score 30
Code Size 1923 Byte
Status RE
Exec Time 295 ms
Memory 8232 KiB

Judge Result

Set Name Subtask All
Score / Max Score 30 / 30 0 / 270
Status
AC × 17
AC × 34
RE × 16
Set Name Test Cases
Subtask atetubou-challenge1.in, subtask_00.txt, subtask_01.txt, subtask_02.txt, subtask_03.txt, subtask_04.txt, subtask_05.txt, subtask_06.txt, subtask_07.txt, subtask_08.txt, subtask_09.txt, subtask_10.txt, subtask_11.txt, subtask_12.txt, subtask_13.txt, subtask_14.txt, subtask_15.txt, subtask_16.txt
All scrambled_00.txt, scrambled_01.txt, scrambled_02.txt, scrambled_03.txt, scrambled_04.txt, scrambled_05.txt, scrambled_06.txt, scrambled_07.txt, scrambled_08.txt, scrambled_09.txt, scrambled_10.txt, scrambled_11.txt, scrambled_12.txt, scrambled_13.txt, scrambled_14.txt, scrambled_15.txt, scrambled_16.txt, scrambled_17.txt, scrambled_18.txt, scrambled_19.txt, scrambled_20.txt, scrambled_21.txt, scrambled_22.txt, scrambled_23.txt, scrambled_24.txt, scrambled_25.txt, scrambled_26.txt, scrambled_27.txt, scrambled_28.txt, scrambled_29.txt, scrambled_30.txt, scrambled_31.txt, scrambled_32.txt, subtask_00.txt, subtask_01.txt, subtask_02.txt, subtask_03.txt, subtask_04.txt, subtask_05.txt, subtask_06.txt, subtask_07.txt, subtask_08.txt, subtask_09.txt, subtask_10.txt, subtask_11.txt, subtask_12.txt, subtask_13.txt, subtask_14.txt, subtask_15.txt, subtask_16.txt
Case Name Status Exec Time Memory
scrambled_00.txt AC 26 ms 864 KiB
scrambled_01.txt AC 55 ms 6644 KiB
scrambled_02.txt AC 55 ms 6776 KiB
scrambled_03.txt AC 53 ms 6692 KiB
scrambled_04.txt AC 55 ms 6816 KiB
scrambled_05.txt AC 59 ms 6748 KiB
scrambled_06.txt AC 52 ms 6820 KiB
scrambled_07.txt AC 57 ms 6824 KiB
scrambled_08.txt AC 57 ms 6692 KiB
scrambled_09.txt AC 54 ms 6820 KiB
scrambled_10.txt AC 54 ms 6696 KiB
scrambled_11.txt RE 288 ms 4520 KiB
scrambled_12.txt RE 289 ms 4516 KiB
scrambled_13.txt RE 280 ms 4640 KiB
scrambled_14.txt RE 295 ms 4520 KiB
scrambled_15.txt RE 278 ms 4512 KiB
scrambled_16.txt RE 288 ms 4524 KiB
scrambled_17.txt RE 280 ms 4512 KiB
scrambled_18.txt RE 282 ms 4512 KiB
scrambled_19.txt RE 283 ms 4636 KiB
scrambled_20.txt RE 278 ms 4512 KiB
scrambled_21.txt RE 288 ms 4776 KiB
scrambled_22.txt AC 55 ms 8220 KiB
scrambled_23.txt AC 60 ms 8232 KiB
scrambled_24.txt AC 60 ms 8224 KiB
scrambled_25.txt AC 68 ms 8228 KiB
scrambled_26.txt AC 63 ms 8232 KiB
scrambled_27.txt RE 277 ms 804 KiB
scrambled_28.txt RE 285 ms 928 KiB
scrambled_29.txt RE 281 ms 924 KiB
scrambled_30.txt RE 287 ms 920 KiB
scrambled_31.txt RE 281 ms 800 KiB
scrambled_32.txt AC 26 ms 868 KiB
subtask_00.txt AC 25 ms 792 KiB
subtask_01.txt AC 54 ms 6684 KiB
subtask_02.txt AC 60 ms 6684 KiB
subtask_03.txt AC 55 ms 6684 KiB
subtask_04.txt AC 55 ms 6824 KiB
subtask_05.txt AC 61 ms 6688 KiB
subtask_06.txt AC 57 ms 6824 KiB
subtask_07.txt AC 57 ms 6816 KiB
subtask_08.txt AC 56 ms 6688 KiB
subtask_09.txt AC 54 ms 6820 KiB
subtask_10.txt AC 55 ms 6692 KiB
subtask_11.txt AC 63 ms 8228 KiB
subtask_12.txt AC 65 ms 8224 KiB
subtask_13.txt AC 63 ms 8228 KiB
subtask_14.txt AC 66 ms 8220 KiB
subtask_15.txt AC 63 ms 8224 KiB
subtask_16.txt AC 26 ms 916 KiB