QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#73136 | #4401. Prize | 12345678 | Compile Error | / | / | C++14 | 2.8kb | 2023-01-22 13:32:01 | 2023-01-22 13:32:02 |
Judging History
你现在查看的是最新测评结果
- [2023-08-10 23:21:45]
- System Update: QOJ starts to keep a history of the judgings of all the submissions.
- [2023-01-22 13:32:02]
- 评测
- 测评结果:Compile Error
- 用时:0ms
- 内存:0kb
- [2023-01-22 13:32:01]
- 提交
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mp make_pair
#define inf 1e9
#define pii pair <int, int>
const int mod = 1e9 + 7;
inline int read () {
int x = 0, f = 1;
char ch = getchar ();
while (ch < '0' || ch > '9') f = ((ch == '-') ? -1 : f), ch = getchar ();
while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar ();
return x * f;
}
inline void write (int x) {
if (x < 0) x = -x, putchar ('-');
if (x >= 10) write (x / 10);
putchar (x % 10 + '0');
}
int n, k, Q, T;
struct Tree {
int Fa[1000005], Rt;
vector <int> G[1000005];
int dep[1000005], siz[1000005], son[1000005], top[1000005];
int dfn[1000005], seq[1000005], tot;
void dfs(int x, int fa) {
dfn[x] = ++tot, seq[tot] = x;
dep[x] = dep[fa] + 1;
siz[x] = 1;
for(auto y : G[x]) {
dfs(y, x);
siz[x] += siz[y];
if(!son[x] || siz[y] > siz[son[x]]) son[x] = y;
}
}
void dfs2(int x) {
int fa = Fa[x];
if(son[fa] == x) top[x] = top[fa];
else top[x] = x;
if(son[x]) dfs2(son[x]);
for(auto y : G[x]) if(y != son[x]) dfs2(y);
}
int LCA(int x, int y) {
while(top[x] != top[y]) {
if(dep[top[x]] < dep[top[y]]) swap(x, y);
x = Fa[top[x]];
}
if(dep[x] > dep[y]) swap(x, y);
return x;
}
void init() {
for(int i = 1; i <= n; i++) {
Fa[i] = read();
if(Fa[i] == -1) Rt = i;
else G[Fa[i]].push_back(i);
}
dfs(Rt, 0), dfs2(Rt);
}
vector <pii> V[1000005];
void add(int x, int y) {
int e = read();
V[x].push_back(mp(y, e));
V[y].push_back(mp(x, -e));
}
int vis[1000005], dis[1000005];
void dfs3(int x, int e) {
if(vis[x]) return ;
vis[x] = 1, dis[x] = e;
for(auto y : V[x]) dfs3(y.first, e + y.second);
}
int Dis(int x, int y) {
int lca = LCA(x, y);
return dis[x] + dis[y] - 2 * dis[lca];
}
}T1, T2;
int a[1000005];
signed main () {
// freopen (".in", "r", stdin);
// freopen (".out", "w", stdout);
n = read(), k = read(), Q = read(), T = read();
T1.init(), T2.init();
for(int i = 1; i <= k; i++) a[i] = T2.seq[i];
sort(a + 1, a + 1 + k, [&] (int A, int B) {return T1.dfn[A] < T1.dfn[B];});
for(int i = 1; i <= k; i++) write(a[i]), putchar(' ');
putchar('\n'), fflush(stdout);
for(int i = 1; i < k; i++) write(a[i]), putchar(' '), write(a[i+1]), putchar('\n');
puts("!"), fflush(stdout);
for(int i = 1; i < k; i++) {
int lca1 = T1.LCA(a[i], a[i+1]), lca2 = T2.LCA(a[i], a[i+1]);
T1.add(lca1, a[i]), T1.add(lca1, a[i+1]), T2.add(lca2, a[i]), T2.add(lca2, a[i+1]);
}
for(int i = 1; i <= k; i++) T1.dfs3(a[i], 0);
sort(a + 1, a + 1 + k, [&] (int A, int B) {return T2.dfn[A] < T2.dfn[B];});
for(int i = 1; i <= k; i++) T2.dfs3(a[i], 0);
while(T--) {
int x = read(), y = read();
write(T1.Dis(x, y)), putchar(' '), write(T2.Dis(x, y)), putchar('\n');
}
fflush(stdout)
return 0;
}
/*
*/
Details
answer.code: In function ‘int main()’: answer.code:104:23: error: expected ‘;’ before ‘return’ 104 | fflush(stdout) | ^ | ; 105 | return 0; | ~~~~~~