제출 #441914

#제출 시각아이디문제언어결과실행 시간메모리
441914keta_tsimakuridze통행료 (IOI18_highway)C++14
51 / 100
310 ms262148 KiB
#include "highway.h" #include<bits/stdc++.h> #define f first #define s second using namespace std; const int Q = 2e5 + 5; /* #include <cstdio> #include <cstdlib> #include <cstring> #include <queue> #include <utility> #include <vector> ///#include "highway.h" namespace { const int MAX_NUM_CALLS = 100; const 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 ( int t = 0; t < graph[v].size(); t++) { pair<int,int> e = graph[v][t]; 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; } */ ///////////////////////////////////////// int timer,out[Q],pos[Q],up[Q],c[Q]; vector<int> x; vector<pair<int,int> > V[Q]; void dfs(int u,int p) { for(int i=0;i<V[u].size();i++) { if(V[u][i].f != p) up[V[u][i].f] = V[u][i].s,c[V[u][i].f] = u,dfs(V[u][i].f,u); } timer++; pos[timer] = u; } void find_pair(int n, std::vector<int> u, std::vector<int> v, int A, int B) { for(int i=0;i<u.size();i++){ V[u[i]].push_back({v[i],i}); V[v[i]].push_back({u[i],i}); } dfs(0,-1); x.resize(u.size()); long long D = ask(x); int l = 1, r = n - 1,S = -1, T = 0; while(l<=r) { int mid = (l+r)/2; for(int i=1;i<n;i++) { if(i < mid) x[up[pos[i]]] = 1; else x[up[pos[i]]] = 0; } long long d = ask(x); if(d == D) { S = pos[mid]; l = mid + 1; } else r = mid - 1; } for(int i = 0; i<n;i++) reverse(V[i].begin(),V[i].end()); timer = 0; dfs(0,-1); l = 1, r = n; while(l<=r) { int mid = (l+r)/2; for(int i=1;i<n;i++) { if(i < mid) x[up[pos[i]]] = 1; else x[up[pos[i]]] = 0; } long long d = ask(x); if(d == D) { T = pos[mid]; l = mid + 1; } else r = mid - 1; } for(int i=0;i<u.size();i++) x[i] = 1; int e = S; while(e) { x[up[e]] = 0; e = c[e]; } if(ask(x) == D) { D /= A; T = S; while(D--) { T = c[T]; } } //cout<<S<<" "<<T<<endl; answer(S,T); } /* 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; }*/

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

highway.cpp: In function 'void dfs(int, int)':
highway.cpp:120:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  120 |  for(int i=0;i<V[u].size();i++) {
      |              ~^~~~~~~~~~~~
highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:127:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  127 |   for(int i=0;i<u.size();i++){
      |               ~^~~~~~~~~
highway.cpp:167:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  167 |   for(int i=0;i<u.size();i++) x[i] = 1;
      |               ~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...