Submission #1771593
Source Code Expand
#include<bits/stdc++.h> using namespace std; int n,t,w; int fa[200010],d[200010]; pair<int,int> q[200010]; map<int,int> h[200010]; int find(int x) {return fa[x]==x?x:fa[x]=find(fa[x]); } int main() {int i,j,x,y,k; map<int,int>::iterator p,p1; scanf("%d",&n); for(i=1;i<n;i++) { scanf("%d%d",&x,&y); h[x][y]=1; h[y][x]=1; d[x]++; d[y]++; } t=1; w=0; for(i=1;i<n;i++) { scanf("%d%d",&x,&y); h[x][y]++; h[y][x]++; d[x]++; d[y]++; if(h[x][y]==2) q[++w]=make_pair(x,y); } for(i=1;i<=n;i++) fa[i]=i; while(t<=w) { x=find(q[t].first); y=find(q[t].second); if(d[x]<d[y]) swap(x,y); h[x][y]-=2; h[y][x]-=2; for(p=h[y].begin();p!=h[y].end();p++) { if((*p).second==0) continue; k=(h[x][(*p).first]+=(*p).second); h[(*p).first][x]+=(*p).second; h[(*p).first][y]-=(*p).second; if(k==2) q[++w]=make_pair(x,(*p).first); } d[x]+=d[y]-2; fa[y]=x; t++; } printf("%s\n",t==n?"YES":"NO"); return 0; }
Submission Info
Submission Time | |
---|---|
Task | E - Blue and Red Tree |
User | xhk |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 1008 Byte |
Status | RE |
Exec Time | 6330 ms |
Memory | 400896 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:17:16: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d",&n); ^ ./Main.cpp:19:23: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] { scanf("%d%d",&x,&y); ^ ./Main.cpp:28:23: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] { scanf("%d%d",&x,&y); ^
Judge Result
Set Name | Sample | All | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 0 / 1400 | ||||||||||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | sample1.txt, sample2.txt, sample3.txt |
All | sample1.txt, sample2.txt, sample3.txt, in1.txt, in10.txt, in11.txt, in12.txt, in13.txt, in14.txt, in15.txt, in16.txt, in17.txt, in18.txt, in19.txt, in2.txt, in20.txt, in21.txt, in22.txt, in23.txt, in24.txt, in25.txt, in26.txt, in27.txt, in28.txt, in29.txt, in3.txt, in30.txt, in31.txt, in32.txt, in33.txt, in34.txt, in35.txt, in36.txt, in37.txt, in38.txt, in39.txt, in4.txt, in40.txt, in41.txt, in42.txt, in43.txt, in44.txt, in45.txt, in46.txt, in47.txt, in5.txt, in6.txt, in7.txt, in8.txt, in9.txt, sample1.txt, sample2.txt, sample3.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
in1.txt | AC | 7 ms | 12544 KB |
in10.txt | AC | 243 ms | 31232 KB |
in11.txt | MLE | 5916 ms | 333568 KB |
in12.txt | MLE | 5333 ms | 295296 KB |
in13.txt | MLE | 5926 ms | 329856 KB |
in14.txt | MLE | 5342 ms | 284800 KB |
in15.txt | MLE | 5062 ms | 284160 KB |
in16.txt | MLE | 4833 ms | 269440 KB |
in17.txt | MLE | 5862 ms | 307840 KB |
in18.txt | MLE | 5948 ms | 329344 KB |
in19.txt | MLE | 5341 ms | 290304 KB |
in2.txt | AC | 7 ms | 12544 KB |
in20.txt | MLE | 5101 ms | 279680 KB |
in21.txt | RE | 5681 ms | 359680 KB |
in22.txt | MLE | 5244 ms | 287488 KB |
in23.txt | MLE | 5491 ms | 296576 KB |
in24.txt | RE | 4838 ms | 292352 KB |
in25.txt | RE | 5971 ms | 329216 KB |
in26.txt | AC | 4371 ms | 243584 KB |
in27.txt | MLE | 5802 ms | 317440 KB |
in28.txt | MLE | 5356 ms | 285440 KB |
in29.txt | MLE | 5211 ms | 280192 KB |
in3.txt | AC | 7 ms | 12544 KB |
in30.txt | MLE | 5499 ms | 297472 KB |
in31.txt | AC | 427 ms | 40704 KB |
in32.txt | TLE | 6330 ms | 400896 KB |
in33.txt | WA | 509 ms | 40704 KB |
in34.txt | AC | 440 ms | 42752 KB |
in35.txt | WA | 432 ms | 40704 KB |
in36.txt | WA | 452 ms | 40704 KB |
in37.txt | AC | 506 ms | 40704 KB |
in38.txt | AC | 440 ms | 40704 KB |
in39.txt | AC | 412 ms | 40704 KB |
in4.txt | AC | 187 ms | 31232 KB |
in40.txt | WA | 375 ms | 40704 KB |
in41.txt | AC | 424 ms | 40704 KB |
in42.txt | AC | 451 ms | 40704 KB |
in43.txt | WA | 468 ms | 40704 KB |
in44.txt | AC | 522 ms | 40704 KB |
in45.txt | AC | 449 ms | 40704 KB |
in46.txt | AC | 394 ms | 40704 KB |
in47.txt | AC | 398 ms | 40704 KB |
in5.txt | AC | 172 ms | 31232 KB |
in6.txt | AC | 386 ms | 40704 KB |
in7.txt | AC | 154 ms | 31232 KB |
in8.txt | AC | 237 ms | 31232 KB |
in9.txt | AC | 200 ms | 31232 KB |
sample1.txt | AC | 7 ms | 12544 KB |
sample2.txt | AC | 7 ms | 12544 KB |
sample3.txt | AC | 7 ms | 12544 KB |