Submission #426432

# Submission time Handle Problem Language Result Execution time Memory
426432 2021-06-14T02:56:02 Z hibye1217 Dreaming (IOI13_dreaming) C++17
10 / 100
51 ms 8516 KB
#ifndef NOTSUBMIT
#include <bits/stdc++.h>
using namespace std;
#include "dreaming.h"
#endif // NOTSUBMIT

// Only Subtask 2
// Will do Subtask 1 later

int n, m;

typedef long long ll;
typedef pair<ll, ll> pl2;
#define fr first
#define sc second
vector<pl2> adj[100020];
int par[100020];

inline int fnd(int a){
	if (par[a] == a){ return a; }
	return par[a] = fnd(par[a]);
}

inline void uni(int a, int b){
	int pa = fnd(a), pb = fnd(b);
	par[pa] = pb;
}

bool chk[100020];
pl2 dfs(int st){
	stack<pl2> stk;
	memset(chk, 0, sizeof(chk));
	stk.push({st, 0}); chk[st] = 1;
	pl2 res = {st, 0};
	while (!stk.empty()){
		int now = stk.top().fr; ll dst = stk.top().sc; stk.pop();
		//cout << "DFS " << now << ' ' << dst << endl;
		if (res.sc < dst){ res = {now, dst}; }
		for (pl2 p : adj[now]){
			int nxt = p.fr; ll d = p.sc;
			if (chk[nxt]){ continue; }
			chk[nxt] = 1;
			stk.push({ nxt, dst+d });
		}
	}
	//cout << endl;
	return res;
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
	for (int i = 0; i < N; i++){ par[i] = i; }
	for (int i = 0; i < M; i++){
		adj[ A[i] ].push_back({ B[i], T[i] });
		adj[ B[i] ].push_back({ A[i], T[i] });
		uni(A[i], B[i]);
	}
	if (M == N-2){
		if (N <= 100){ // Subtask 2
			ll ans = 1e12;
			for (int i = 0; i < N; i++){
				for (int j = i+1; j < N; j++){
					if (fnd(i) == fnd(j)){ continue; }
					//cout << "PAIR " << i << ' ' << j << endl;
					adj[i].push_back({j, L});
					adj[j].push_back({i, L});
					ans = min( ans, dfs( dfs(0).fr ).sc );
					adj[i].pop_back();
					adj[j].pop_back();
				}
			}
			return ans;
		}
		else{ // Subtask 1, Not Implemented Yet
			return -1;
		}
	}
	return -1;
}
# Verdict Execution time Memory Grader output
1 Incorrect 51 ms 8516 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2764 KB Output is correct
2 Correct 24 ms 2764 KB Output is correct
3 Correct 9 ms 2764 KB Output is correct
4 Correct 20 ms 2764 KB Output is correct
5 Correct 27 ms 2756 KB Output is correct
6 Correct 31 ms 2764 KB Output is correct
7 Correct 4 ms 2764 KB Output is correct
8 Correct 5 ms 2764 KB Output is correct
9 Correct 3 ms 2648 KB Output is correct
10 Correct 4 ms 2764 KB Output is correct
11 Correct 30 ms 2772 KB Output is correct
12 Correct 26 ms 2772 KB Output is correct
13 Correct 29 ms 2764 KB Output is correct
14 Correct 14 ms 2772 KB Output is correct
15 Correct 3 ms 2636 KB Output is correct
16 Correct 23 ms 2772 KB Output is correct
17 Correct 3 ms 2764 KB Output is correct
18 Correct 16 ms 2760 KB Output is correct
19 Correct 11 ms 2768 KB Output is correct
20 Correct 23 ms 2772 KB Output is correct
21 Correct 25 ms 2764 KB Output is correct
22 Correct 28 ms 2764 KB Output is correct
23 Correct 5 ms 2764 KB Output is correct
24 Correct 22 ms 2772 KB Output is correct
25 Correct 29 ms 2656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 51 ms 8516 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 28 ms 5444 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2764 KB Output is correct
2 Correct 24 ms 2764 KB Output is correct
3 Correct 9 ms 2764 KB Output is correct
4 Correct 20 ms 2764 KB Output is correct
5 Correct 27 ms 2756 KB Output is correct
6 Correct 31 ms 2764 KB Output is correct
7 Correct 4 ms 2764 KB Output is correct
8 Correct 5 ms 2764 KB Output is correct
9 Correct 3 ms 2648 KB Output is correct
10 Correct 4 ms 2764 KB Output is correct
11 Correct 30 ms 2772 KB Output is correct
12 Correct 26 ms 2772 KB Output is correct
13 Correct 29 ms 2764 KB Output is correct
14 Correct 14 ms 2772 KB Output is correct
15 Correct 3 ms 2636 KB Output is correct
16 Correct 23 ms 2772 KB Output is correct
17 Correct 3 ms 2764 KB Output is correct
18 Correct 16 ms 2760 KB Output is correct
19 Correct 11 ms 2768 KB Output is correct
20 Correct 23 ms 2772 KB Output is correct
21 Correct 25 ms 2764 KB Output is correct
22 Correct 28 ms 2764 KB Output is correct
23 Correct 5 ms 2764 KB Output is correct
24 Correct 22 ms 2772 KB Output is correct
25 Correct 29 ms 2656 KB Output is correct
26 Incorrect 2 ms 2636 KB Output isn't correct
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 51 ms 8516 KB Output isn't correct
2 Halted 0 ms 0 KB -