跳到正文

C02fe

365402

-I opened myself to the gentle indifference of the world.-

在洛谷打开
资料、奖项与版本

资料

编号
365402
抓取

奖项

2021 CSP-J
一等奖

主页

比利比利

C++
#include<bits/stdc++.h>
using namespace std;

int main(){

}

神帖

I opened myself to the gentle indifference of the world.

存代码

C++
#include<bits/stdc++.h>
using namespace std;
long long n,m,lsh[300005],s[100005],len,t;
long long sum[100005];
struct sb{
	int fi,la;
}xc[114514],lr[114514];
int main(){
	t=1;
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	{
		cin>>xc[i].fi>>xc[i].la;
		lsh[t]=xc[i].fi;
		t++;
	}
	for(int i=1;i<=m;i++)
	{
		cin>>lr[i].fi>>lr[i].la;
		lsh[t]=lr[i].fi;
		t++;
		lsh[t]=lr[i].la;
		t++;
	}
	sort(lsh+1,lsh+t);
	//cout<<unique(lsh+1,lsh+t)-lsh-1;
	len=unique(lsh+1,lsh+t)-lsh-1;
	for(int i=1;i<=n;i++)
	{
		int x1=lower_bound(lsh+1,lsh+1+len,xc[i].fi);
		s[x1]+=xc[i].la;
		cout<<x1;
	}
	return 0;
}

拓扑模板

C++
#include<bits/stdc++.h>
using namespace std;
int n,m,x,y,r[10005];
vector<int > s[10005];
queue<int> q;
int main(){
	cin>>n>>m;
	for(int i=1;i<=m;i++)
	{
		cin>>x>>y;
		s[x].push_back(y);
		r[y]++;
	}
	for(int i=1;i<=n;i++)
	{
		if(r[i]==0)
		{
			q.push(i);
		}
	}
	while(!q.empty())
	{
		int t=q.front();
		q.pop();
		cout<<t<<" ";
		for(int i=0;i<s[t].size();i++)
		{
			int id=s[t][i];
			r[id]--;
			if(r[id]==0)
			{
				q.push(id);
			}
		}
	}
	return 0;
}
C++
#include<bits/stdc++.h>
using namespace std;
int n,m,x,y,r[10005],fl[10005];
vector<int > s[10005];
int dfs(int a)
{
	cout<<a<<" ";
	for(int i=0;i<s[a].size();i++)
	{
		int id=s[a][i];
		r[id]--;
		if(r[id]==0&&fl[id]==0)
		{
			fl[id]=1;
			dfs(id); 
		}
	}
	return 0;
}
int main(){
	cin>>n>>m;
	for(int i=1;i<=m;i++)
	{
		cin>>x>>y;
		s[x].push_back(y);
		r[y]++;
	}
	for(int i=1;i<=n;i++)
	{
		if(r[i]==0&&fl[i]==0)
		{
			//cout<<"ss"<<endl;
			fl[i]=1;
			dfs(i);
		}
	}
	return 0;
}

还没有收录这位用户的文章。