Run ID 作者 问题 语言 测评结果 时间 内存 代码长度 提交时间
11603 ydks 【USACO】草地种植 revegetate(USACO 2019) C++ 运行出错 0 MS 260 KB 1363 2022-10-06 14:46:39

Tests(0/10):


#include<bits/stdc++.h> using namespace std; typedef pair<int, int> PII; const int N = 400; int p[N], vis[N]; PII a[N]; vector<int> xl[N]; int ans[N]; int h[N], e[N], ne[N], idx; inline void add(int a, int b){ e[idx] = b, ne[idx] = h[a], h[a] = idx++; } int pd(int x, int s){ for(int i = h[x]; i != -1; i = ne[i]){ int j = e[i]; if(s == ans[j]) return 0; } return 1; } void dfs(int i, int x){ // cout << i << " " << x << endl; vis[i] = 1; ans[i] = x; if(x == 4) x = 1; else x++; for(auto t : xl[i]){ if(!vis[t] || (pd(t, x) && x < ans[t])){ dfs(t, x); } } } int main(){ freopen("tmp.in", "r", stdin); memset(h, -1, sizeof h); int n, m; cin >> n >> m; for(int i = 1; i <= m; i ++){ cin >> a[i].first >> a[i].second; if(a[i].second < a[i].first) swap(a[i].first, a[i].second); xl[a[i].first].push_back(a[i].second); xl[a[i].second].push_back(a[i].first); add(a[i].first, a[i].second); add(a[i].second, a[i].first); } for(int i = 1; i <= n; i ++){ sort(xl[i].begin(), xl[i].end()); // cout << "xl[" << i << "]: "; // for(auto x : xl[i]) cout << x << " "; // cout << endl; } for(int i = 1; i <= n; i ++){ if(!vis[i]) dfs(i, 1); } for(int i = 1; i <= n; i ++){ cout << ans[i]; } }


测评信息: