제출 #511433

#제출 시각아이디문제언어결과실행 시간메모리
511433Tizariox악어의 지하 도시 (IOI11_crocodile)C++14
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using pii = pair<int, int>;

#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define F0R1(i, a) for (int i = 1; i <= (a); i++)
#define FORd(i, a, b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i, a) for (int i = (a)-1; i >= 0; i--)
#define F0Rd1(i, a) for (int i = a; i > 0; i--)
#define SORT(vec) sort(vec.begin(), vec.end())
#define S0RT(arr, n) sort(arr, arr + n)

#define pA first
#define pB second
#define MOD 1000000007
#define nl "\n"
#define pb push_back

int n, m, k;
vector<int> exits;

class cmp {
  public:
	bool operator()(vector<int> a, vector<int> b) { return a[1] > b[1]; }
};

pii dist[100000]; // 2 smallest distances to each node
vector<pii> adj[100000];
bool shortestVis[100000]; // whether the shortest path for each node has already been taken

void dijkstra() { // traceback
	for (int i = 0; i < n; i++) {
		dist[i] = {1e9, 1e9};
		shortestVis[i] = false;
	}
	priority_queue<vector<int>, vector<vector<int>>, cmp> nodes;
	for (int root : exits) {
		dist[root] = {0, 0};
		nodes.push({root, 0, -1});
		shortestVis[root] = true;
	}
	while (!nodes.empty()) {
		int node = nodes.top()[0];
		int minDist = nodes.top()[1];
		int parent = nodes.top()[2];
		nodes.pop();
		if (!shortestVis[node]) {
			shortestVis[node] = true;
			continue;
		} else if (minDist > dist[node].pB) {
			continue;
		}
		for (pii i : adj[node]) {
			int neighbor = i.pA;
			int length = i.pB;
			if (minDist + length < dist[neighbor].pA) {
				dist[neighbor].pB = dist[neighbor].pA;
				dist[neighbor].pA = minDist + length;
				nodes.push({neighbor, dist[neighbor].pA, node});
			} else if (minDist + length < dist[neighbor].pB) {
				dist[neighbor].pB = minDist + length;
				nodes.push({neighbor, dist[neighbor].pB, node});
			}
		}
	}
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> m >> k;
	for (int i = 0; i < m; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		adj[a].pb(pii(b, c));
		adj[b].pb(pii(a, c));
	}
	FOR(i, 0, k) { 
		int num;
		cin >> num;
		exits.pb(num);
	}
	dijkstra();
	cout << dist[0].pB << nl;
}

// 5 7 2
// 0 2 4 
// 0 3 3
// 3 2 2
// 2 1 10
// 0 1 100
// 0 4 7
// 3 4 9
// 1 3

컴파일 시 표준 에러 (stderr) 메시지

crocodile.cpp: In function 'void dijkstra()':
crocodile.cpp:48:7: warning: unused variable 'parent' [-Wunused-variable]
   48 |   int parent = nodes.top()[2];
      |       ^~~~~~
/usr/bin/ld: /tmp/cckdGw9g.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccPLhfWi.o:crocodile.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/cckdGw9g.o: in function `main':
grader.cpp:(.text.startup+0x36): undefined reference to `travel_plan(int, int, int (*) [2], int*, int, int*)'
collect2: error: ld returned 1 exit status