社区讨论
初用NOI LINUX求助
学术版参与者 6已保存回复 11
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 11 条
- 当前快照
- 1 份
- 快照标识符
- @mhz47v41
- 此快照首次捕获于
- 2025/11/15 01:11 3 个月前
- 此快照最后确认于
- 2025/11/16 14:20 3 个月前
CPP
#include<bits/stdc++.h>
#define d(x) cerr<<#x<<"="<<x<<endl
#define ll long long
#define sparkle cerr<<"happyhappyhappy"<<endl
using namespace std;
const int maxn=200005;
const int mod=1000000007;
ll dp[maxn];
struct Edge
{
ll v;
bool istrue;
};
vector<Edge> q[maxn];
inline void dfs1(ll now,ll from)
{
for(auto v:q[now])
{
if (v.v==from)
{
continue;
}
dfs1(v.v,now);
dp[now]+=dp[v.v]+v.istrue;
}
}
inline void dfs2(ll now,ll from)
{
for(auto v:q[now])
{
if (v.v==from)
{
continue;
}
dp[v.v]=dp[now]+(1-2*v.istrue);
dfs2(v.v,now);
}
}
inline void solve()
{
ll n,u,v;
cin>>n;
for(int i=1;i<n;i++)
{
cin>>u>>v;
q[u].push_back({v,0});
q[v].push_back({u,1});
}
for(int i=1;i<=n;i++)
dp[i]=0;
dfs1(1,0);
dfs2(1,0);
ll minn=LLONG_MAX;
for(int i=1;i<=n;i++)
{
minn=min(minn,dp[i]);
}
cout<<minn<<endl;
for(int i=1;i<=n;i++)
{
if(dp[i]==minn)
cout<<i<<" ";
}
cout<<endl;
}
int main()
{
freopen("data.in","r",stdin);
freopen("data.out","w",stdout);
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int _;
_=1;
while(_--)
{
solve();
}
return 0;
}
为什么同样的代码在输入相同的情况下在OJ上(将文件输入输出注释掉了)和在Sublime上的输出不一样?
回复
共 11 条回复,欢迎继续交流。
正在加载回复...