Submission #2230659
Source Code Expand
#include <map> #include <set> #include <queue> #include <cstdio> #include <algorithm> using namespace std; #define fir first #define sec second typedef pair<int, int> PI; namespace io { const int maxb = 1 << 15; char b[maxb], *s = b, *t = b; bool Getchar(char &ch) { return ch = s == t && (t = (s = b) + fread(b, 1, maxb, stdin)) == b ? 0 : *s ++; } } int Getint() { using namespace io; char ch; while (Getchar(ch) && (ch < '0' || ch > '9')); int s = ch - '0'; while (Getchar(ch) && ch >= '0' && ch <= '9') s = s * 10 + ch - '0'; return s; } const int maxn = 1e5 + 10; set<int> adj[maxn]; map<int, int> cnt[maxn]; int main() { int n = Getint(), m = n - 1 << 1; for (int i = 1; i <= m; ++ i) { int x = Getint(), y = Getint(); if (x > y) swap(x, y); adj[x].insert(y); adj[y].insert(x); ++ cnt[x][y]; } queue<PI> Q; for (int i = 1; i <= n; ++ i) { for (set<int> :: iterator it = adj[i].begin(); it != adj[i].end(); ++ it) { if (*it > i) break; if (cnt[*it][i] > 1) Q.push(PI(*it, i)); } } int count = 0; while (!Q.empty()) { int x = Q.front().fir, y = Q.front().sec; Q.pop(); if (adj[x].empty() || adj[y].empty()) continue; ++ count; adj[x].erase(y); adj[y].erase(x); -- cnt[x][y]; if (adj[x].size() < adj[y].size()) swap(x, y); for (set<int> :: iterator it = adj[y].begin(); it != adj[y].end(); ++ it) { adj[*it].erase(y); adj[*it].insert(x); int p = min(x, *it), q = max(x, *it); if (++ cnt[p][q] == 2) Q.push(PI(p, q)); } adj[y].clear(); } if (count == n - 1) puts("YES"); else puts("NO"); return 0; }
Submission Info
Submission Time | |
---|---|
Task | E - Blue and Red Tree |
User | survivor |
Language | C++14 (GCC 5.4.1) |
Score | 0 |
Code Size | 1679 Byte |
Status | WA |
Exec Time | 261 ms |
Memory | 37760 KB |
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 | 9600 KB |
in10.txt | AC | 217 ms | 37760 KB |
in11.txt | WA | 228 ms | 32768 KB |
in12.txt | WA | 230 ms | 32768 KB |
in13.txt | WA | 250 ms | 32768 KB |
in14.txt | WA | 261 ms | 32768 KB |
in15.txt | WA | 231 ms | 32768 KB |
in16.txt | WA | 229 ms | 32768 KB |
in17.txt | WA | 230 ms | 32768 KB |
in18.txt | WA | 211 ms | 32768 KB |
in19.txt | WA | 235 ms | 32768 KB |
in2.txt | AC | 5 ms | 9600 KB |
in20.txt | WA | 238 ms | 32768 KB |
in21.txt | AC | 244 ms | 33152 KB |
in22.txt | AC | 236 ms | 33152 KB |
in23.txt | AC | 239 ms | 33152 KB |
in24.txt | AC | 243 ms | 33152 KB |
in25.txt | AC | 218 ms | 33280 KB |
in26.txt | AC | 250 ms | 32768 KB |
in27.txt | WA | 221 ms | 32768 KB |
in28.txt | WA | 249 ms | 32768 KB |
in29.txt | WA | 238 ms | 32768 KB |
in3.txt | AC | 5 ms | 9600 KB |
in30.txt | WA | 232 ms | 32768 KB |
in31.txt | WA | 195 ms | 37760 KB |
in32.txt | WA | 195 ms | 37760 KB |
in33.txt | WA | 200 ms | 37760 KB |
in34.txt | WA | 207 ms | 37760 KB |
in35.txt | WA | 208 ms | 37760 KB |
in36.txt | WA | 210 ms | 37760 KB |
in37.txt | WA | 214 ms | 37760 KB |
in38.txt | WA | 202 ms | 37760 KB |
in39.txt | WA | 183 ms | 37760 KB |
in4.txt | AC | 205 ms | 37760 KB |
in40.txt | WA | 207 ms | 37760 KB |
in41.txt | AC | 198 ms | 37760 KB |
in42.txt | AC | 188 ms | 37760 KB |
in43.txt | AC | 201 ms | 37760 KB |
in44.txt | AC | 223 ms | 37760 KB |
in45.txt | AC | 200 ms | 37760 KB |
in46.txt | AC | 194 ms | 37760 KB |
in47.txt | AC | 193 ms | 37760 KB |
in5.txt | AC | 214 ms | 37760 KB |
in6.txt | AC | 194 ms | 37760 KB |
in7.txt | AC | 217 ms | 37760 KB |
in8.txt | AC | 194 ms | 37760 KB |
in9.txt | AC | 210 ms | 37760 KB |
sample1.txt | AC | 5 ms | 9600 KB |
sample2.txt | AC | 5 ms | 9600 KB |
sample3.txt | AC | 5 ms | 9600 KB |