2 条题解

  • 0
    @ 2026-8-4 11:04:13

    非常简单,优势在我!!!

    #include<bits/stdc++.h>
    #define int long long
    using namespace std;
    constexpr int N=1e5+10;
    int n,m,k;
    map<pair<int,int>,int>mp;
    signed main(){
    	ios::sync_with_stdio(false);
    	cin.tie(0),cout.tie(0);
    	while(cin>>n>>m){
    		mp.clear();k=0;
    		for(int i=1;i<=m;i++){
    			int x,y;
    			cin>>x>>y;
    			if(x>y)swap(x,y);
    			if(!mp[{x,y}]++)k++;
    		}
    		for(int i=1;i<=m;i++){
    			int x,y;
    			cin>>x>>y;
    			if(x>y)swap(x,y);
    			if(!--mp[{x,y}])k--;
    		}
    		cout<<(!k?"YES":"NO")<<"\n";
    	}
    }
    
    • 0
      @ 2026-1-21 0:57:10
      
      #include <bits/stdc++.h>
      using namespace std;
      
      bool solve(int n,int m)
      {
          vector<int> a(m), b(m);
          for (int i = 0; i < m; i++) cin >> a[i] >> b[i];
          vector<int> c(m), d(m);
          for (int i = 0; i < m; i++) cin >> c[i] >> d[i];
          
          map< pair<int, int> , vector<int> > edge_to_id;
          for (int j = 0; j < m; j++) {
              edge_to_id[{min(a[j], b[j]), max(a[j], b[j])}].push_back(j);
          }
          
          vector<bool> used(m, false);
          
          for (int i = 0; i < m; i++) {
              pair<int, int> tno = {min(c[i], d[i]), max(c[i], d[i])};
              if (edge_to_id[tno].empty()) return 0;
      
              bool flg = false;
              for (int j : edge_to_id[tno]) {
                  if (!used[j] && ((c[i] == a[j] && d[i] == b[j]) || (c[i] == b[j] && d[i] == a[j]))) {
                      used[j] = true;
                      flg = true;
                      break;
                  }
              }
              if (!flg) return 0;
          }
          
          for (int i = 0; i < m; i++) if (!used[i]) return 0;
          
          return 1;
      }
      
      int main() {
      	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
          int n, m;
          while(cin >> n >> m){
      	  if(solve(n,m)) cout << "YES\n";
      	  else cout << "NO\n";
          }
      	return 0;
      }
      
      
      
      • 1

      *【STL:map】判断两个无向图是否相同

      信息

      ID
      4714
      时间
      1000ms
      内存
      256MiB
      难度
      7
      标签
      递交数
      126
      已通过
      31
      上传者