제출 #123266

#제출 시각아이디문제언어결과실행 시간메모리
123266imyujin통행료 (IOI18_highway)C++14
100 / 100
343 ms11412 KiB
#include "highway.h" #include<vector> #include<queue> #include<bitset> using namespace std; #define MAXN 90005 typedef long long lint; typedef pair<int, int> pii; int N, M; lint d; int se; vector<pii> ed[MAXN]; int da[MAXN], db[MAXN]; bitset<MAXN> chk; int num[MAXN]; void bfs(int x, int dx[]) { queue<int> q; for(int i = 0; i < N; i++) dx[i] = -1; dx[x] = 0; q.push(x); while(!q.empty()) { int t = q.front(); q.pop(); for(auto a : ed[t]) if(dx[a.first] == -1) { dx[a.first] = dx[t] + 1; q.push(a.first); } } } int f(int x, int dx[], int dy[]) { queue<int> q; vector<int> con; for(int i = 0; i < N; i++) chk[i] = false; q.push(x); chk[x] = true; while(!q.empty()) { int t = q.front(); q.pop(); con.push_back(t); for(auto a : ed[t]) if(dx[a.first] < dy[a.first] && !chk[a.first]) { chk[a.first] = true; q.push(a.first); } } for(int i = 0; i < N; i++) num[i] = -1; for(int i = 0; i < con.size(); i++) num[con[i]] = i; /* for(auto a : con) printf("%d ", a); printf("\n"); */ vector<int> w(M, 0); int s = 0, e = con.size() - 1; int m = (s + e) / 2; for(int i = m + 1; i <= e; i++) for(auto a : ed[con[i]]) w[a.second] = 1; while(s < e) { //printf("s = %d, e = %d\n", s, e); if(ask(w) == d) { e = m; m = (s + e) / 2; for(int i = m + 1; i <= e; i++) for(auto a : ed[con[i]]) w[a.second] = 1; } else { s = m + 1; m = (s + e) / 2; for(int i = s; i <= m; i++) for(auto a : ed[con[i]]) if(num[a.first] < i) w[a.second] = 0; } } return con[s]; } void find_pair(int n, vector<int> U, vector<int> V, int A, int B) { N = n; M = U.size(); vector<int> w(M, 0); for(int i = 0; i < M; i++) { ed[U[i]].push_back(make_pair(V[i], i)); ed[V[i]].push_back(make_pair(U[i], i)); } d = ask(w); int s = 0, e = M - 1, m = (M-1) / 2; for(int i = m + 1; i <= e; i++) w[i] = 1; while(s < e) { if(ask(w) != d) { s = m + 1; m = (s + e) / 2; for(int i = s; i <= m; i++) w[i] = 0; } else { e = m; m = (s + e) / 2; for(int i = m + 1; i <= e; i++) w[i] = 1; } } se = s; int alpha = U[se], beta = V[se]; //printf("se=%d(%d, %d)\n", se, alpha, beta); bfs(alpha, da); bfs(beta, db); //for(int i = 0; i < N; i++) printf("[%d %d]\n", da[i], db[i]); answer(f(alpha, da, db), f(beta, db, da)); }

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

highway.cpp: In function 'int f(int, int*, int*)':
highway.cpp:55:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0; i < con.size(); i++) num[con[i]] = i;
                 ~~^~~~~~~~~~~~
#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...