QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#784319 | #8757. 图 | hotdogseller | TL | 811ms | 13656kb | C++14 | 2.7kb | 2024-11-26 14:32:28 | 2024-11-26 14:32:29 |
Judging History
answer
#include<bits/stdc++.h>
#define maxn 200008
#define pii pair<int,int>
#define int long long
using namespace std;
inline int read(){
int lre=0,f=1;
char c=getchar();
while(!isdigit(c)){
if(c=='-'){
f=-1;
}
c=getchar();
}
while(isdigit(c)){
lre=(lre<<3)+(lre<<1)+(c-'0');
c=getchar();
}
return lre*f;
}
inline int f(int a,int b){
return (a<<32)|b;
}
int T;
int n,m,s,t;
map<int,set<int> > ga[maxn];
map<int,int> mp;
void add(int u,int v,int y){
mp[f(u,v)]++;
ga[u][y].insert(v);
}
void del(int u,int v,int y){
mp[f(u,v)]--;
if(mp[f(u,v)]==0)ga[u][y].erase(ga[u][y].find(v));
}
int cnt=0;
map<int,map<int,int> > root;
int f_f(int x,int y){
if(root[y][x]==0)root[y][x]=x;
if(root[y][x]!=x){
root[y][x]=f_f(root[y][x],y);
}
return root[y][x];
}
void merge(int u,int v,int y){
if(root[y][u]==0)root[y][u]=u;
if(root[y][v]==0)root[y][v]=v;
root[y][f_f(u,y)]=f_f(v,y);
}
bool okay=false;
vector<int> v;
bool visited[maxn];
void dfs(int x,int goal,int y){
// cout<<"x="<<x<<endl;
v.push_back(x);visited[x]=true;
if(x==goal){
printf("%lld ",v.size());
for(int i:v){
printf("%lld ",i);
}
putchar('\n');
okay=true;
}else{
set<int>::iterator it;
for(it=ga[x][y].begin();it!=ga[x][y].end();it++){
int v=*it;
if(visited[v])continue;
// cout<<x<<"->"<<v<<endl;
dfs(v,goal,y);
if(okay){
del(x,v,y);del(v,x,y);
break;
}
}
}
v.pop_back();visited[x]=false;
}
void solve(){
n=read();m=read();
// cout<<"new!!!!!!!!!!!!!!!!!!!!!n="<<n<<" m="<<m<<"!!!!!"<<endl;
mp.clear();cnt=0;root.clear();
for(int i=1;i<=n;i++){
ga[i].clear();
}
for(int i=1;i<=m;i++){
int u=read(),v=read();
// cout<<"fu="<<f_f(u,cnt)<<" fv="<<f_f(v,cnt)<<endl;
if(cnt==0||f_f(u,cnt)==f_f(v,cnt)){
// cout<<"new!"<<endl;
cnt++;merge(u,v,cnt);
add(u,v,cnt);add(v,u,cnt);
}else{
int l=1,r=cnt,mid,ind;
while(l<=r){
mid=l+r>>1;
if(f_f(u,mid)==f_f(v,mid)){
l=mid+1;
}else{
ind=mid;
r=mid-1;
}
}
merge(u,v,ind);
add(u,v,ind);add(v,u,ind);
}
}
// cout<<"cnt="<<cnt<<endl;
for(int i=1;i<=n;i++){
if(f_f(i,cnt)!=i){
s=i;t=f_f(i,cnt);
break;
}
}
// cout<<"res:";
printf("%lld %lld\n",s,t);
int k=(m+n-2)/(n-1);
// cout<<"k="<<k<<endl;
for(int i=1;i<=k;i++){
// cout<<"No "<<i<<".";
okay=false;
dfs(s,t,i);
}
}
signed main(){
// freopen("3.in","r",stdin);
memset(visited,0,sizeof(visited));
T=read();
while(T--){
// cout<<"t="<<T<<endl;
solve();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 109ms
memory: 13336kb
input:
10000 2 20 1 2 1 2 2 1 1 2 1 2 2 1 1 2 2 1 1 2 1 2 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 1 2 2 1 2 20 2 1 2 1 2 1 2 1 2 1 1 2 1 2 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 2 20 1 2 2 1 1 2 1 2 2 1 2 1 1 2 1 2 2 1 2 1 1 2 1 2 1 2 1 2 2 1 1 2 1 2 1 2 2 1 2 1 2 20 1 2 2 1 2 1 1 2 1 2 1 2 2 1 1 2 2 ...
output:
2 1 2 2 1 2 2 1 2 2 1 2 2 1 2 2 1 2 2 1 2 2 1 2 2 1 2 2 1 2 2 1 2 2 1 2 2 1 2 2 1 2 2 1 2 2 1 2 2 1 2 2 1 2 2 1 2 2 1 2 2 1 1 2 2 1 2 2 1 2 2 1 2 2 1 2 2 1 2 2 1 2 2 1 2 2 1 2 2 1 2 2 1 2 2 1 2 2 1 2 2 1 2 2 1 2 2 1 2 2 1 2 2 1 2 2 1 2 2 1 2 2 1 2 2 1 2 2 1 2...
result:
ok Answer correct. (10000 test cases)
Test #2:
score: 0
Accepted
time: 199ms
memory: 13388kb
input:
10000 5 20 2 1 2 5 5 3 3 1 4 5 1 4 4 3 4 5 3 5 5 4 2 3 5 2 3 4 3 5 1 4 4 3 4 2 2 1 1 3 5 1 5 20 4 2 1 3 1 2 4 5 2 4 3 1 5 3 5 1 4 5 4 3 2 4 1 4 4 3 5 2 1 2 3 5 1 5 4 1 3 4 4 3 5 20 1 4 1 3 1 5 5 1 4 5 3 4 4 5 2 3 1 2 2 4 4 5 4 5 2 4 2 5 4 2 4 3 4 2 2 5 2 1 3 1 5 20 2 5 2 3 4 5 4 2 3 4 2 1 5 4 2 5 2 ...
output:
5 1 3 5 2 1 3 5 4 1 4 5 3 4 1 4 5 4 2 1 3 5 3 1 4 3 4 4 2 1 3 3 4 5 3 2 4 3 2 4 3 2 4 3 4 2 4 4 1 3 2 4 4 5 1 2 2 4 2 2 4 2 3 4 5 2 4 1 4 4 5 2 1 3 4 2 1 4 4 5 3 1 3 4 3 1 3 4 2 1 2 1 4 2 3 5 1 4 2 3 5 1 3 2 3 1 3 2 4 1 4 2 3 5 1 2 1 4 2 5 4 1 3 2 4 1 3 2 5 1 3 2 5 1 3 2...
result:
ok Answer correct. (10000 test cases)
Test #3:
score: 0
Accepted
time: 226ms
memory: 13500kb
input:
10000 10 20 9 4 8 6 2 10 2 9 7 10 4 6 9 4 2 1 4 7 1 5 7 2 4 1 5 9 7 6 8 2 9 4 5 9 9 8 7 3 2 4 10 20 3 8 8 9 8 7 9 2 3 10 9 3 8 1 9 4 8 9 4 7 7 5 5 10 1 3 3 4 3 7 3 8 3 9 1 4 3 6 2 4 10 20 7 6 8 10 3 8 2 8 4 8 4 8 4 6 4 1 1 7 4 6 5 9 5 2 4 7 10 9 6 7 10 5 2 4 4 1 3 2 4 9 10 20 2 1 9 8 7 6 2 10 9 5 4 ...
output:
2 8 5 2 9 4 6 8 2 2 8 4 2 4 9 8 1 4 4 1 8 9 4 3 1 3 4 2 1 4 4 1 2 4 1 3 4 7 1 2 4 1 4 2 6 4 3 9 5 1 2 2 4 2 3 4 10 2 2 10 4 2 7 4 10 2 2 10 3 2 3 10 1 3 3 1 7 3 3 1 10 3 4 1 8 6 3 3 9 2 3 9 2 3 9 3 3 4 9 1 10 2 1 10 3 1 5 10 2 1 10 7 8 3 7 5 8 2 7 8 2 7 8 4 9 7 4 6 10 1 8 ...
result:
ok Answer correct. (10000 test cases)
Test #4:
score: 0
Accepted
time: 136ms
memory: 13400kb
input:
2000 50 50 6 10 21 26 12 42 29 2 3 30 3 28 7 44 44 37 11 4 23 12 49 14 34 41 35 48 33 6 27 9 33 1 33 31 43 35 32 31 20 42 27 40 39 29 34 38 21 15 31 17 3 33 17 18 15 44 50 22 20 25 28 44 23 32 3 23 25 30 50 20 17 2 21 41 46 35 26 7 34 45 34 19 21 10 44 4 28 22 36 21 4 49 44 39 4 36 2 15 21 38 50 50 ...
output:
2 15 8 2 17 31 33 3 28 44 15 2 2 15 7 10 6 7 36 24 9 37 10 2 7 10 15 24 9 15 34 5 8 1 10 36 14 24 2 15 24 4 19 17 4 10 31 1 47 24 36 28 22 3 13 21 26 42 14 49 19 2 4 19 20 11 4 20 47 35 11 2 20 11 1 45 11 1 24 3 31 12 41 22 9 30 19 45 2 1 45 1 13 3 1 2 13 2 1 13 18 19 7 18 46 42 36 26 ...
result:
ok Answer correct. (2000 test cases)
Test #5:
score: 0
Accepted
time: 811ms
memory: 13656kb
input:
200 50 1000 6 33 31 2 17 37 27 22 36 1 35 12 31 3 8 36 22 15 40 45 13 23 23 24 50 46 41 48 49 35 15 30 14 6 7 24 38 27 43 19 30 16 16 31 49 21 47 44 33 9 27 32 48 23 24 33 25 12 23 50 6 27 20 21 48 11 42 23 8 36 3 34 8 14 17 30 27 1 14 40 37 5 23 24 6 24 5 35 38 43 31 48 25 33 4 13 6 37 22 24 31 32 ...
output:
27 42 6 27 6 33 24 23 42 6 27 6 24 22 43 42 3 27 40 42 5 27 14 18 16 42 11 27 50 38 2 37 49 9 29 36 16 42 5 27 19 6 37 42 7 27 44 41 24 30 45 42 10 27 38 8 43 6 26 39 10 21 42 5 27 9 41 10 42 6 27 20 22 36 13 42 17 27 9 22 10 32 28 21 35 24 33 1 49 26 25 45 39 42 7 27 3 14 20 8 40 42 16 ...
result:
ok Answer correct. (200 test cases)
Test #6:
score: -100
Time Limit Exceeded
input:
20 100 10000 77 84 14 62 84 5 4 67 99 44 54 18 39 53 58 88 32 3 61 19 76 14 28 72 92 34 20 1 14 66 98 25 53 99 55 40 13 70 42 62 32 41 93 14 74 66 92 62 42 12 94 35 26 65 82 85 100 34 79 47 87 59 4 92 46 4 77 63 17 62 32 23 46 76 61 26 89 41 10 18 17 64 55 61 89 42 8 71 75 89 2 81 9 63 42 32 23 34 7...
output:
5 6 14 5 84 77 63 76 14 62 42 89 20 99 48 91 6 7 5 64 41 87 60 67 6 12 5 66 96 91 72 46 98 31 76 94 69 6 12 5 73 39 68 71 72 98 36 63 65 74 6 11 5 47 17 76 20 42 26 78 33 95 6 12 5 18 96 29 27 76 14 57 62 71 91 6 12 5 31 65 86 15 10 13 43 99 88 80 6 9 5 41 77 43 46 1 49 40 6 14 5 29 36 98 30...