Submission #1771575
Source Code Expand
#include<bits/stdc++.h> using namespace std; int n,t,w; int d[200010]; pair<int,int> q[200010]; map<int,int> h[200010]; 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); } while(t<=w) { x=q[t].first; y=q[t].second; if(d[x]<d[y]) swap(x,y); h[x][y]--; h[y][x]--; for(p=h[y].begin();p!=h[y].end();p++) { 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; 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 | 849 Byte |
Status | WA |
Exec Time | 6331 ms |
Memory | 441856 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:13:16: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%d",&n); ^ ./Main.cpp:15: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:24: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 | 5 ms | 10496 KB |
in10.txt | AC | 118 ms | 29568 KB |
in11.txt | MLE | 3713 ms | 270592 KB |
in12.txt | MLE | 3998 ms | 295040 KB |
in13.txt | MLE | 3735 ms | 260480 KB |
in14.txt | TLE | 6323 ms | 337280 KB |
in15.txt | TLE | 6328 ms | 409088 KB |
in16.txt | MLE | 3718 ms | 270976 KB |
in17.txt | TLE | 6327 ms | 378752 KB |
in18.txt | WA | 3248 ms | 219444 KB |
in19.txt | WA | 3986 ms | 252800 KB |
in2.txt | AC | 5 ms | 10496 KB |
in20.txt | WA | 4441 ms | 233472 KB |
in21.txt | MLE | 4221 ms | 284416 KB |
in22.txt | MLE | 3805 ms | 268032 KB |
in23.txt | TLE | 6326 ms | 378368 KB |
in24.txt | TLE | 6326 ms | 380032 KB |
in25.txt | TLE | 6325 ms | 361984 KB |
in26.txt | MLE | 4263 ms | 306176 KB |
in27.txt | TLE | 6331 ms | 405248 KB |
in28.txt | TLE | 6330 ms | 441856 KB |
in29.txt | TLE | 6327 ms | 390016 KB |
in3.txt | AC | 5 ms | 10496 KB |
in30.txt | MLE | 4332 ms | 308352 KB |
in31.txt | WA | 379 ms | 39040 KB |
in32.txt | WA | 370 ms | 39040 KB |
in33.txt | WA | 377 ms | 39040 KB |
in34.txt | WA | 395 ms | 39040 KB |
in35.txt | WA | 119 ms | 29696 KB |
in36.txt | WA | 495 ms | 39680 KB |
in37.txt | WA | 373 ms | 39040 KB |
in38.txt | WA | 335 ms | 39040 KB |
in39.txt | WA | 341 ms | 39040 KB |
in4.txt | AC | 114 ms | 29568 KB |
in40.txt | WA | 112 ms | 29696 KB |
in41.txt | AC | 381 ms | 39040 KB |
in42.txt | AC | 400 ms | 39040 KB |
in43.txt | AC | 443 ms | 39040 KB |
in44.txt | AC | 409 ms | 39040 KB |
in45.txt | AC | 119 ms | 29696 KB |
in46.txt | AC | 337 ms | 39040 KB |
in47.txt | AC | 113 ms | 29696 KB |
in5.txt | AC | 116 ms | 29568 KB |
in6.txt | AC | 337 ms | 39040 KB |
in7.txt | AC | 116 ms | 29568 KB |
in8.txt | AC | 117 ms | 29568 KB |
in9.txt | AC | 115 ms | 29568 KB |
sample1.txt | AC | 5 ms | 10496 KB |
sample2.txt | AC | 5 ms | 10496 KB |
sample3.txt | AC | 5 ms | 10496 KB |