Submission #64236802


Source Code Expand

Copy
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
int ec[412345];
struct edge_s {
int to, cost;
} *es[412345];
void ae(int from, int to, int cost) {
es[from] = realloc(es[from], sizeof(*es[from]) * (ec[from] + 1));
if (es[from] == NULL) exit(2);
es[from][ec[from]++] = (struct edge_s){ to, cost };
}
struct q_s {
int64_t cost;
int node;
};
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>

int ec[412345];

struct edge_s {
	int to, cost;
} *es[412345];

void ae(int from, int to, int cost) {
	es[from] = realloc(es[from], sizeof(*es[from]) * (ec[from] + 1));
	if (es[from] == NULL) exit(2);
	es[from][ec[from]++] = (struct edge_s){ to, cost };
}

struct q_s {
	int64_t cost;
	int node;
};

int qsize = 0, qcap = 0;
struct q_s* q;

void qadjust(int pos) {
	for (;;) {
		int i;
		int minpos = pos;
		for (i = 1; i <= 2; i++) {
			int c = pos * 2 + i;
			if (c < qsize && q[minpos].cost > q[c].cost) minpos = c;
		}
		if (minpos == pos) {
			if (pos == 0) return;
			pos = (pos - 1) / 2;
		} else {
			struct q_s temp = q[pos];
			q[pos] = q[minpos];
			q[minpos] = temp;
			pos = minpos;
		}
	}
}

void qadd(int64_t cost, int node) {
	if (qsize >= qcap) {
		qcap = qsize + 1;
		q = realloc(q, sizeof(*q) * qcap);
		if (q == NULL) exit(2);
	}
	q[qsize++] = (struct q_s){ cost, node };
	qadjust(qsize - 1);
}

struct q_s qget(void) {
	struct q_s res;
	if (qsize <= 0) exit(42);
	res = q[0];
	if (--qsize > 0) {
		q[0] = q[qsize];
		qadjust(0);
	}
	return res;
}

int64_t mincost[412345];

int main(void) {
	int N, M, X;
	int i;
	if (scanf("%d%d%d", &N, &M, &X) != 3) return 1;
	for (i = 0; i < M; i++) {
		int u, v;
		if (scanf("%d%d", &u, &v) != 2) return 1;
		ae(u, v, 1);
		ae(N + v, N + u, 1);
	}
	for (i = 1; i < N; i++) {
		ae(i, N + i, X);
		ae(N + i, i, X);
	}
	ae(N + N, N, 0);
	memset(mincost, -1, sizeof(mincost));
	mincost[1] = 0;
	qadd(0, 1);
	while (qsize > 0) {
		struct q_s cur = qget();
		if (mincost[cur.node] == cur.cost) {
			for (i = 0; i < ec[cur.node]; i++) {
				int nn = es[cur.node][i].to;
				int64_t nc = mincost[cur.node] + es[cur.node][i].cost;
				if (mincost[nn] < 0 || nc < mincost[nn]) {
					mincost[nn] = nc;
					qadd(nc, nn);
				}
			}
		}
	}
	printf("%" PRId64 "\n", mincost[N]);
	return 0;
}

Submission Info

Submission Time
Task E - Flip Edge
User mikecat
Language C (gcc 12.2.0)
Score 425
Code Size 2023 Byte
Status AC
Exec Time 175 ms
Memory 27036 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 425 / 425
Status
AC × 4
AC × 70
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 01_random_31.txt, 01_random_32.txt, 01_random_33.txt, 01_random_34.txt, 01_random_35.txt, 01_random_36.txt, 01_random_37.txt, 01_random_38.txt, 01_random_39.txt, 01_random_40.txt, 01_random_41.txt, 01_random_42.txt, 01_random_43.txt, 01_random_44.txt, 01_random_45.txt, 01_random_46.txt, 01_random_47.txt, 01_random_48.txt, 01_random_49.txt, 01_random_50.txt, 01_random_51.txt, 01_random_52.txt, 01_random_53.txt, 01_random_54.txt, 01_random_55.txt, 01_random_56.txt, 01_random_57.txt, 01_random_58.txt, 01_random_59.txt, 01_random_60.txt, 01_random_61.txt, 01_random_62.txt, 01_random_63.txt, 01_random_64.txt, 01_random_65.txt, 01_random_66.txt, 01_random_67.txt, 01_random_68.txt, 01_random_69.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 2 ms 4808 KB
00_sample_01.txt AC 2 ms 4788 KB
00_sample_02.txt AC 2 ms 4944 KB
00_sample_03.txt AC 2 ms 4844 KB
01_random_04.txt AC 170 ms 23820 KB
01_random_05.txt AC 148 ms 23944 KB
01_random_06.txt AC 155 ms 22572 KB
01_random_07.txt AC 161 ms 23876 KB
01_random_08.txt AC 148 ms 23796 KB
01_random_09.txt AC 157 ms 22560 KB
01_random_10.txt AC 161 ms 23856 KB
01_random_11.txt AC 163 ms 23940 KB
01_random_12.txt AC 153 ms 22548 KB
01_random_13.txt AC 161 ms 23720 KB
01_random_14.txt AC 163 ms 23828 KB
01_random_15.txt AC 150 ms 22460 KB
01_random_16.txt AC 175 ms 23764 KB
01_random_17.txt AC 158 ms 23916 KB
01_random_18.txt AC 158 ms 22464 KB
01_random_19.txt AC 161 ms 23732 KB
01_random_20.txt AC 147 ms 23784 KB
01_random_21.txt AC 147 ms 22532 KB
01_random_22.txt AC 158 ms 23700 KB
01_random_23.txt AC 165 ms 23852 KB
01_random_24.txt AC 153 ms 22476 KB
01_random_25.txt AC 157 ms 23684 KB
01_random_26.txt AC 156 ms 23912 KB
01_random_27.txt AC 148 ms 22544 KB
01_random_28.txt AC 157 ms 23824 KB
01_random_29.txt AC 145 ms 23912 KB
01_random_30.txt AC 145 ms 22456 KB
01_random_31.txt AC 133 ms 17320 KB
01_random_32.txt AC 35 ms 9232 KB
01_random_33.txt AC 82 ms 13696 KB
01_random_34.txt AC 115 ms 22520 KB
01_random_35.txt AC 66 ms 12504 KB
01_random_36.txt AC 77 ms 14800 KB
01_random_37.txt AC 67 ms 11696 KB
01_random_38.txt AC 39 ms 18460 KB
01_random_39.txt AC 64 ms 13484 KB
01_random_40.txt AC 101 ms 20996 KB
01_random_41.txt AC 67 ms 20464 KB
01_random_42.txt AC 18 ms 7388 KB
01_random_43.txt AC 119 ms 20020 KB
01_random_44.txt AC 52 ms 13492 KB
01_random_45.txt AC 143 ms 21868 KB
01_random_46.txt AC 106 ms 22116 KB
01_random_47.txt AC 140 ms 27028 KB
01_random_48.txt AC 93 ms 22024 KB
01_random_49.txt AC 168 ms 26892 KB
01_random_50.txt AC 98 ms 21984 KB
01_random_51.txt AC 149 ms 27036 KB
01_random_52.txt AC 91 ms 22028 KB
01_random_53.txt AC 150 ms 26948 KB
01_random_54.txt AC 92 ms 22048 KB
01_random_55.txt AC 146 ms 26936 KB
01_random_56.txt AC 95 ms 22052 KB
01_random_57.txt AC 98 ms 22008 KB
01_random_58.txt AC 93 ms 22040 KB
01_random_59.txt AC 129 ms 21940 KB
01_random_60.txt AC 156 ms 22112 KB
01_random_61.txt AC 146 ms 22080 KB
01_random_62.txt AC 114 ms 15072 KB
01_random_63.txt AC 110 ms 15232 KB
01_random_64.txt AC 112 ms 15080 KB
01_random_65.txt AC 1 ms 4800 KB
01_random_66.txt AC 2 ms 4960 KB
01_random_67.txt AC 2 ms 4864 KB
01_random_68.txt AC 13 ms 20900 KB
01_random_69.txt AC 7 ms 11988 KB


2025-03-28 (Fri)
06:56:59 +09:00