coding2024 @ 2024-08-01 09:56:01
//括号法
#include<iostream>
using namespace std;
const int N=1e4+10;
char a[N];
int main()
{
int n,m;
cin>>n>>m;
while(m--)
{
int x,y;
cin>>x>>y;
if(x!=y)
{
if(a[x]==')')a[x]='\0';
else a[x]='(';
if(a[y]=='(')a[y]='\0';
else a[y]=')';
}
else
{
if(a[x]=='\0')a[x]='#';
}
}
int ans=0,sum=0;
for(int i=0;i<=n;i++)
{
if(a[i]=='(')sum++;
if(!sum&&a[i]!='#')ans++;
if(a[i]==')')sum--;
}
//for(int i=0;i<=n;i++)cout<<a[i];
cout<<ans<<endl;
return 0;
}
by coding2024 @ 2024-08-01 13:33:53
ok 我调好了