| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 | 
|---|---|---|---|---|---|---|---|
| 55118 | ainta | Telegraph (JOI16_telegraph) | C++17 | 110 ms | 8424 KiB | 
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
vector<int>E[101000];
int n, C[101000], w[101000], Deg[101000], Q[101000], head, tail, v[101000], chk;
long long res;
void Do(int a) {
	int t = a, i, rr = 1e9;
	vector<int>T;
	while (1) {
		v[t] = 1;
		T.push_back(t);
		t = w[t];
		if (t == a)break;
	}
	if (T.size() == n) {
		chk = 1;
		return;
	}
	for (auto &x : T) {
		int Mx1 = -1, Mx2 = 0;
		for (auto &y : E[x]) {
			if (Deg[y])Mx1 = max(Mx1, C[y]);
			else Mx2 = max(Mx2, C[y]);
		}
		rr = min(rr, Mx1 - Mx2);
	}
	rr = max(rr, 0);
	res += rr;
}
int main() {
	int i;
	scanf("%d", &n);
	for (i = 1; i <= n; i++) {
		scanf("%d%d", &w[i],&C[i]);
		Deg[w[i]]++;
		E[w[i]].push_back(i);
	}
	for (i = 1; i <= n; i++) {
		vector<int>T;
		for (auto &t : E[i]) {
			T.push_back(C[t]);
		}
		if (!T.empty()) {
			sort(T.begin(), T.end());
			for (int j = 0; j < T.size() - 1; j++) {
				res += T[j];
			}
		}
	}
	for (i = 1; i <= n; i++)if (!Deg[i])Q[++tail] = i;
	while (head < tail) {
		int x = Q[++head];
		v[x] = 1;
		Deg[w[x]]--;
		if (!Deg[w[x]])Q[++tail] = w[x];
	}
	for (i = 1; i <= n; i++) {
		if (!v[i]) {
			Do(i);
		}
	}
	if (chk) {
		printf("0\n");
		return 0;
	}
	printf("%lld\n", res);
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
