Submission #1074520

#TimeUsernameProblemLanguageResultExecution timeMemory
1074520TB_Highway Tolls (IOI18_highway)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> #pragma GCC optimize("Ofast,inline") using namespace std; #define ll long long #define fo(i, n) for(ll i = 0; i<(n); i++) #define pb push_back #define F first #define S second #define deb(x) cout << #x << " = " << (x) << endl #define deb2(x, y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl typedef vector<ll> vl; typedef vector<vl> vvl; namespace { constexpr int MAX_NUM_CALLS = 100; constexpr long long INF = 1LL << 61; int N, M, A, B, S, T; std::vector<int> U, V; std::vector<std::vector<std::pair<int, int>>> graph; bool answered, wrong_pair; int num_calls; int read_int() { int x; if (scanf("%d", &x) != 1) { fprintf(stderr, "Error while reading input\n"); exit(1); } return x; } void wrong_answer(const char *MSG) { printf("Wrong Answer: %s\n", MSG); exit(0); } } // namespace long long ask(const std::vector<int> &w) { if (++num_calls > MAX_NUM_CALLS) { wrong_answer("more than 100 calls to ask"); } if (w.size() != (size_t)M) { wrong_answer("w is invalid"); } for (size_t i = 0; i < w.size(); ++i) { if (!(w[i] == 0 || w[i] == 1)) { wrong_answer("w is invalid"); } } std::vector<bool> visited(N, false); std::vector<long long> current_dist(N, INF); std::queue<int> qa, qb; qa.push(S); current_dist[S] = 0; while (!qa.empty() || !qb.empty()) { int v; if (qb.empty() || (!qa.empty() && current_dist[qa.front()] <= current_dist[qb.front()])) { v = qa.front(); qa.pop(); } else { v = qb.front(); qb.pop(); } if (visited[v]) { continue; } visited[v] = true; long long d = current_dist[v]; if (v == T) { return d; } for (auto e : graph[v]) { int vv = e.first; int ei = e.second; if (!visited[vv]) { if (w[ei] == 0) { if (current_dist[vv] > d + A) { current_dist[vv] = d + A; qa.push(vv); } } else { if (current_dist[vv] > d + B) { current_dist[vv] = d + B; qb.push(vv); } } } } } return -1; } void answer(int s, int t) { if (answered) { wrong_answer("answered not exactly once"); } if (!((s == S && t == T) || (s == T && t == S))) { wrong_pair = true; } answered = true; } void find_pair(int N, std::vector<int> U, std::vector<int> V, int A, int B) { int M = U.size(); vl invalid(N, 0); for (int j = 0; j < 50; ++j) { std::vector<int> w(M); for (int i = 0; i < M; ++i) { w[i] = rand()%2; } long long toll = ask(w); // deb(toll); queue<pair<ll, ll>> pq; pq.push({0, 0}); vl seen(N, 0); ll cost, pos; vector<vector<pair<ll, ll>>> adj(N); fo(i, M){ adj[U[i]].pb({V[i], (w[i]?B:A)}); adj[V[i]].pb({U[i], (w[i]?B:A)}); } while(!pq.empty()){ tie(cost, pos) = pq.front(); pq.pop(); cost = -cost; if(seen[pos]) continue; // deb2(pos, cost); invalid[pos]|=cost!=toll; seen[pos] = 1; for(auto &[v, w] : adj[pos]){ pq.push({-cost-w, v}); } } } int ans = 0; fo(i, N) if(!invalid[i]) ans = i; // fo(i, N) deb(invalid[i]); answer(0, ans); } int main() { N = read_int(); M = read_int(); A = read_int(); B = read_int(); S = read_int(); T = read_int(); U.resize(M); V.resize(M); graph.assign(N, std::vector<std::pair<int, int>>()); for (int i = 0; i < M; ++i) { U[i] = read_int(); V[i] = read_int(); graph[U[i]].push_back({V[i], i}); graph[V[i]].push_back({U[i], i}); } answered = false; wrong_pair = false; num_calls = 0; find_pair(N, U, V, A, B); if (!answered) { wrong_answer("answered not exactly once"); } if (wrong_pair) { wrong_answer("{s, t} is wrong"); } printf("Accepted: %d\n", num_calls); return 0; }

Compilation message (stderr)

/usr/bin/ld: /tmp/ccaMbh4A.o: in function `ask(std::vector<int, std::allocator<int> > const&)':
grader.cpp:(.text+0xa0): multiple definition of `ask(std::vector<int, std::allocator<int> > const&)'; /tmp/cc1Cg7sD.o:highway.cpp:(.text+0x100): first defined here
/usr/bin/ld: /tmp/ccaMbh4A.o: in function `answer(int, int)':
grader.cpp:(.text+0x210): multiple definition of `answer(int, int)'; /tmp/cc1Cg7sD.o:highway.cpp:(.text+0xa0): first defined here
/usr/bin/ld: /tmp/ccaMbh4A.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/cc1Cg7sD.o:highway.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status