QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#370616 | #6354. 4 | Tx_Lcy | WA | 11ms | 144500kb | C++14 | 2.0kb | 2024-03-29 13:50:03 | 2024-03-29 13:50:03 |
Judging History
answer
//A tree without skin will surely die.
//A man without face will be alive.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define all(x) (x).begin(),(x).end()
#define rep(i,j,k) for (int i=j;i<=k;++i)
#define per(i,j,k) for (int i=j;i>=k;--i)
int const N=3e6+10;
int u[N],v[N],d[N],fa[N];ll ans3,ans4,nw;
bool vis[N],gk[N];
vector<int>a[N],s[N];
inline void solve(){
int n,m;cin>>n>>m;
rep(i,1,m) cin>>u[i]>>v[i],++d[u[i]],++d[v[i]];
for (int i=1;i<=m;++i){
if (d[u[i]]>d[v[i]]) swap(u[i],v[i]);
if (d[u[i]]==d[v[i]] && u[i]>v[i]) swap(u[i],v[i]);
a[u[i]].push_back(v[i]);
}
int ct=0;
unordered_map<ll,int>mp;
for (int i=1;i<=n;++i){
for (auto v:a[i]) fa[v]=i;
for (auto v:a[i])
for (auto w:a[v])
if (fa[w]==i){
++ans3;
if (!mp[1ll*v*N+w]) mp[1ll*v*N+w]=++ct;
s[mp[1ll*v*N+w]].push_back(i);
}
}
rep(i,1,m) a[v[i]].push_back(u[i]);
vector< pair<int,int> >id;
rep(i,1,ct){
int sz=0;
for (auto j:s[i]) sz+=a[j].size();
id.push_back({sz,i});
}
sort(all(id)),reverse(all(id));
set<int>ss;
for (auto k:id){
int i=k.second;
for (auto j:s[i]){
if (!vis[j]){
ss.insert(j),vis[j]=1;
for (auto P:a[j]) nw+=vis[P];
}
gk[j]=1;
}
vector<int>del;
for (auto i:ss)
if (!gk[i]) del.push_back(i);
for (auto i:del){
ss.erase(i),vis[i]=0;
for (auto P:a[i]) nw-=vis[P];
}
for (auto j:s[i]) gk[j]=0;
ans4+=nw;
}
cout<<n<<' '<<m<<' '<<ans3<<' '<<ans4<<'\n';
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
int t=1;
// cin>>t;
while (t--) solve();
cerr<<"Time: "<<(double)clock()/CLOCKS_PER_SEC<<" s\n";
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 11ms
memory: 144500kb
input:
5 9 1 2 1 3 1 4 1 5 2 3 2 4 2 5 3 4 3 5
output:
5 9 7 2
result:
wrong answer 1st numbers differ - expected: '2', found: '5'