QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#814073 | #9881. Diverge and Converge | ucup-team3161# | RE | 1ms | 4008kb | C++17 | 1.9kb | 2024-12-14 15:00:06 | 2024-12-14 15:00:08 |
Judging History
answer
#include<bits/stdc++.h>
#define For(i,x,y) for (int i=(x);i<=(y);i++)
#define FOR(i,x,y) for (int i=(x);i<(y);i++)
#define Dow(i,x,y) for (int i=(x);i>=(y);i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<int,int> pa;
inline ll read(){
ll x;
scanf("%lld",&x);
return x;
}
const int N = 1010;
int n,ans2[N];
pa e[N],ee[N];
set<pa>e1[N],e2[N];
int col[N];
inline void dfs(int u,int fa,int c){
col[u]=c;
for (auto [v,id]:e1[u]) if (v!=fa){
dfs(v,u,c);
}
}
int fa[N],fid[N];
inline void Dfs(int u){
for (auto [v,id]:e2[u]) if (v!=fa[u]){
fa[v]=u,fid[v]=id;
Dfs(v);
}
}
int main(){
n=read();
For(i,1,n-1){
int x=read(),y=read();
e1[x].insert(mp(y,i));
e1[y].insert(mp(x,i));
e[i]=mp(x,y);
}
For(i,1,n-1){
int x=read(),y=read();
e2[x].insert(mp(y,i));
e2[y].insert(mp(x,i));
ee[i]=mp(x,y);
}
For(i,1,n-1){
auto [x,y]=e[i];
dfs(x,y,0);
dfs(y,x,1);
bool flag=0;
fa[x]=0,fid[x]=0,Dfs(x);
for (int u=y;u;u=fa[u]){
int v=fa[u];
if (v){
if (col[u]!=col[v]&&fid[u]>0){
flag=1;
ans2[i]=fid[u];
break;
}
}
}
assert(flag);
e1[x].erase(mp(y,i));
e1[y].erase(mp(x,i));
e2[x].insert(mp(y,-i));
e2[y].insert(mp(x,-i));
auto [x2,y2]=ee[ans2[i]];
e2[x2].erase(mp(y2,ans2[i]));
e2[y2].erase(mp(x2,ans2[i]));
e1[x2].insert(mp(y2,-ans2[i]));
e1[y2].insert(mp(x2,-ans2[i]));
//printf("%d %d\n",i,ans2[i]);
}
For(i,1,n-1) printf("%d ",i);
puts("");
For(i,1,n-1) printf("%d ",ans2[i]);
puts("");
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3920kb
input:
4 1 2 2 3 3 4 1 2 2 4 2 3
output:
1 2 3 1 3 2
result:
ok Correct, N = 4
Test #2:
score: 0
Accepted
time: 0ms
memory: 4008kb
input:
2 1 2 2 1
output:
1 1
result:
ok Correct, N = 2
Test #3:
score: 0
Accepted
time: 0ms
memory: 3996kb
input:
7 1 2 1 3 2 4 2 5 3 6 3 7 1 5 1 6 1 7 5 2 6 3 7 4
output:
1 2 3 4 5 6 1 2 6 4 5 3
result:
ok Correct, N = 7
Test #4:
score: -100
Runtime Error
input:
1000 780 67 364 281 934 245 121 472 460 233 574 534 91 687 91 832 413 613 815 638 519 196 992 120 150 157 198 365 643 700 279 698 623 215 578 330 869 333 874 570 879 697 897 671 962 670 108 137 779 9 988 91 919 314 696 722 431 270 810 692 769 49 254 915 737 580 229 888 379 612 19 161 787 346 280 753...